Beautiful side-effects! (q = q++)

Kurt Guntheroth kurt at tc.fluke.COM
Fri Jun 28 02:36:43 AEST 1991


> "q = q++;" SHOULD leave q unchanged:  evaluating the
> right hand side we get a value (q BEFORE the increment).  That is
> the value that is supposed to go to the left hand side.  The question
> is WHEN the post-increment is done.

K&R says nothing about when the increment's side effect is processed, and
ANSI says specifically that it is undefined.  The side effect may be applied
AFTER the assignment.  You are probably used to the informal PDP11 semantics
where q++ generates an increment instruction, but no all architectures or
compilers choose this method.  A better example is 

    *p++ = *p++;

which has three side effects that may be processed in arbitrary order.



More information about the Comp.lang.c mailing list