Can va_arg() be used as an lvalue?
Stephen Clamage
steve at taumet.com
Sun Aug 5 05:22:23 AEST 1990
sandra%jensen.utah.edu at cs.utah.edu (Sandra Loosemore) writes:
>The title says it all: is it legitimate, portable usage to treat
>va_arg() as an lvalue? Specifically, can I take the address of its
>return value?
The ANSI C standard says (section 4.8.1.2):
"The va_arg macro expands to an expression that has the type and value
of the next argument in the call."
An expression is not an lvalue. If you need to take the address of
the parameter (as for passing the address to another routine), you
can assigned it to a local temp and take the address of that.
That is, instead of
foo(&va_arg(ap, T));
you write
T temp = va_arg(ap, T);
foo(&temp);
The latter has the same effect and is legal and portable.
--
Steve Clamage, TauMetric Corp, steve at taumet.com
More information about the Comp.lang.c
mailing list