*p++ = *p and more
wsmith at uiucdcsb.CS.UIUC.EDU
wsmith at uiucdcsb.CS.UIUC.EDU
Thu Apr 3 05:54:00 AEST 1986
I think compilers can do the post-increment anytime they feel like it
with in the statement. The semantics of a[i] = b[i++]; isn't
defined so the compiler can do whatever it wants. Even if that means
that both i's are evaluated before the increment is done.
f(i++,i++,i++,i++); is a similar statement. Most compilers do a
reasonable thing although you don't know a priori if it is evaluated
left to right or right to left. The Tartan C compiler optimizes it so
that there aren't even 4 increments done. Only one increment per statement
per variable is unambiguous so that is all the compiler seems to do.
The moral of this story: I something is undefined in a language, don't do it.
You're adding compiler dependencies and are generally asking for
trouble.
(lint would complain about such a construct: "order of evaluation undefined")
Bill Smith
ihnp4!uiucdcs!wsmith
More information about the Comp.lang.c
mailing list