Mail Archives: djgpp-workers/1999/06/01/14:21:19
Eli,
Thanks for running the tests.
I've created a macro to detect when the optional arguments are 
present. But I don't know how portable across compiler versions it is:
#define __dj_HAVE_OPTIONAL_ARGS(x) \
  ((int *)__builtin_frame_address(1) - (int *)__builtin_next_arg(x) - 2)
where x is the last non-optional argument. An example:
void func_with_opt_args(int x, ...)
{
  if (__dj_HAVE_OPTIONAL_ARGS(x))
    printf("Have optional args.\n");
  else
    printf("Do not have optional args.\n");
}
int main()
{
  func_with_optional_args(1, 2);
  func_with_optional_args(1);
  return 0;
}
If it is portable between different compiler versions, the macro could be 
used in open and fcntl to avoid reading arguments from the stack that 
aren't there.
--- 
Mark Elbrecht, snowball3 AT bigfoot DOT com
http://snowball.frogspace.net/
- Raw text -