[Bug c/50581] stdarg doesn't support array types

Wolfgang at Solfrank dot net gcc-bugzilla@gcc.gnu.org
Sun Oct 2 16:09:00 GMT 2011


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50581

--- Comment #6 from Wolfgang at Solfrank dot net 2011-10-02 16:08:51 UTC ---
(In reply to comment #5)
> On Sat, 1 Oct 2011, Wolfgang at Solfrank dot net wrote:
> 
> > > Passing va_list as a function argument is generally hard, whether or not 
> > > variadic, since you don't know whether it will be passed by reference or 
> > > by value or what the type of the address of a va_list parameter will be.  
> > > Portable code needs to pass a pointer to va_list or a structure containing 
> > > va_list or use some other such means of avoiding dependence on whether 
> > > va_list is an array.
> > 
> > Huh?  What about vprintf and friends?  They are defined to take a va_list as
> > their last parameter.
> 
> There are some things you can do - for example, calling those functions in 
> accordance with the rules given in the C standard.  There are various 
> things that cause problems - for example, taking the address of a 
> parameter declared as a va_list (because the parameter type may have been 
> changed from va_list to pointer-to-element-of-va_list as part of the 
> parameter type adjustment of parameters declared as arrays, so the type of 
> &parameter may not be va_list *).

But I don't want to take the address of a va_list parameter.  I just want to
handle it with stuff defined in stdarg.h.

Actually, I'm not sure why va_list is defined as an array in some of the
architectures.  The problem wouldn't arise if va_list were just defined as the
structure that it's currently defined as an array of.

Anyway, I still consider it a bug that gcc when called with -std=c99 compiles
va_arg with array type without any hint into code that cannot possibly be
useful, as it expects the array to be passed by value to the variadic function.



More information about the Gcc-bugs mailing list