Mail Archives: djgpp/2003/04/20/13:16:38
Hello.
Eric Sosman wrote:
>
> Gisle Vanem wrote:
> >
> > I'm porting some code from Watcom to gcc/djgpp and encountered
> > tons of warnings on illegal use of va_arg(). So I cooked up a little
> > test:
> >
> > #include <stdarg.h>
> > char x;
> > void foo (va_list arg)
>
> Hold on; stop right there. You've included <stdarg.h>, but you're
> using the argument list declaration from the pre-Standard <varargs.h>
> (or <vararg.h> with some compilers). The two are not the same, they
> are not interchangeable, and they are *definitely* not miscible.
[snip]
Are you sure that's happening? What if some function calls foo like this:
void
myfunc (int someval, ...)
{
va_list arg;
va_start(arg, someval);
foo(arg);
va_end(arg);
}
I think this is legal according to the C99 standard. From section 7.15
"Variable arguments <stdarg.h>":
"The object ap may be passed as an argument to
another function; if that function invokes the va_arg macro with parameter ap,
the
value of ap in the calling function is indeterminate and shall be passed to
the va_end
macro prior to any further reference to ap."
ap is the va_list - i.e.: arg in the function myfunc above.
Regards,
--
Richard Dawe [ http://www.phekda.freeserve.co.uk/richdawe/ ]
- Raw text -