lvalues and ++

Chris Torek chris at mimsy.UUCP
Sun Dec 14 01:43:32 AEST 1986


In article <31da677c.809c at apollo.uucp> mishkin at apollo.uucp
(Nathaniel Mishkin) writes:
>I am having problems with the construct:
>	char *p; 
>	*((long *)p)++;

We just went through this one.  Is someone reduplicating old news
with new dates?

The construct is not legal C, though some compilers accept it.  A
cast is semantically equivalent to an assignment to an unnamed
temporary variable of the given type.  If the postincrement were
to do anything, it would have to increment that unnamed temporary,
so the change would be lost forever.  Any compiler that increments
`p' by `sizeof (long)' is doubly wrong: once for accepting the
illegal construct, and again for incrementing the wrong variable!
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP:	seismo!mimsy!chris	ARPA/CSNet:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list