A cast pointer is NOT an lvalue!? (ANSI C)

Doug Gwyn gwyn at smoke.ARPA
Sun Oct 9 10:32:50 AEST 1988


In article <479 at midgard.mn.org> dal at syntel.UUCP (Dale Schumacher) writes:
>   value = *((long *) argp)++;

Rather than answer your questions directly, let me explain what is wrong
with this attempted usage.

A cast is the same as assignment to an unnamed temporary variable.
The ++ in your example would have to increment the temporary variable,
not the original variable argp.  That is clearly not what you wanted.

The result of a cast has never been an lvalue for just this reason.
Some compilers have been sloppy about this.

Anyway, you should be using either the old <varargs.h> or the new
<stdarg.h> macros to pick up arguments from a variable argument list.
What you were trying to do cannot be done portably any other way.



More information about the Comp.lang.c mailing list