Passing a `va_list *'

Doug Gwyn gwyn at smoke.BRL.MIL
Tue Oct 31 01:09:26 AEST 1989


In article <MCGRATH.89Oct28150927 at paris.Berkeley.EDU> mcgrath at paris.Berkeley.EDU (Roland McGrath) writes:
>I don't see the problem with whatever type `va_list' is.  You can take the
>address of an object of any type (though not every storage class), and
>dereference the pointer thus obtained.

I'm not sure there is a problem, but you need to check carefully what
happens when va_list is an array type (which is permitted but not
required by the Standard).  I'm away from my copy of the Standard now,
but for example if va_arg() were permitted to be a function, *args in
the inner function would be an attempt to pass an array to va_args(),
not just the name of an array (which would be converted to a pointer
to the array's first element) as in the top-level function.  I forget
whether this usage would also result in conversion to a pointer to
the first element, but if not then it is illegal (and if it did
work, would result in the wrong type being passed to va_args()).  I'll
have to look this up and let you know.

In any case &array will do something different in older PCC implementations
than in Standard C (and is officially not allowed according to K&R1), so if
the code has to work in both <varargs.h> and <stdarg.h> environments, it
may not be portable.

I wish I remembered why we allowed (in one draft, even required) the
va_list to be an array type.  It sure is a nuisance.



More information about the Comp.std.c mailing list