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

jim frost madd at world.std.com
Sun Jun 30 04:06:35 AEST 1991


kurt at tc.fluke.COM (Kurt Guntheroth) writes:
>> "q = q++;" SHOULD leave q unchanged

>K&R says nothing about when the increment's side effect is processed, and
>ANSI says specifically that it is undefined.

Both K&R 1 and 2 say that the behavior is undefined (p 50 and 53-54
respectively, I know 'em by heart) as does ANSI.

With respect to the gcc versus vcc code difference: note that gcc
produced more efficient code by evaluating in a different order.  This
is precisely the reason K&R give for leaving the order undefined.

Happy hacking,

jim



More information about the Comp.lang.c mailing list