incrementing after a cast

Herbert Kanner kanner at apple.UUCP
Thu Dec 4 05:37:17 AEST 1986


We would like to solicit some opinions on the legality of the
following, which is one way of implementing varargs for, e.g., printf:

	foo()
	{
		sometype L;
		char *chp;

		L = *((sometype *) chp)++;
	}

Both the portable C compiler and lint happily accept this construct.
The idea of the cast is to force chp to be incremented by the size of
sometype.

Our problem arises with the allegation that K&R makes this construct
illegal.  On page 214 (syntax summary), the only legal context for ++
is given to be lvalue++, and (type-name) expression is a case of
expression which, according to that syntax, cannot be an lvalue.
-- 
Herb Kanner
Apple Computer, Inc.
{idi, ios, nsc}!apple!kanner



More information about the Comp.lang.c mailing list