#Trivia
25-Jul-86 00:02:53
Sb: #27744-#Trivia
Fm: Don Curtis/SYSOP 76703,4321
To: Larry Phillips/ICUG 74025,636
This message turned up in search, but its forum couldn’t be identified from the original transcript, so it may not be linked into its thread.
You are right about the warning, however it is warning about when the store
of the variable is done. The precedence is specifically listed in a standard
table with the ++ a 2nd level precedence and the = a 14th level precedence.
The exact warning in K&R is that: In any expression involving side effects,
there can be subtle dependencies on the order in which varibales taking part
in the expression are stored.
The side effect occurs on how and when the compiler decides to do the store
of i back into i after the increment (or for that fact, where it does the
increment itself). It can legally fetch i (1), do a second fetch of i (1)
and increment the 2nd fetch. It can then store the first fetch back into i
thus completeing the equation. It can then go ahead and store the
incremented value, thus making i = 2.
It can also legally fetch the value of i (1), do the increment in memory
directly on the variable so it now = 2 and then do the store of the fetched
value thus completing the equation but returning a value of 1.
To me, the 2nd is more "logical" and is what my compilers come up with, but
both are legal.
I know, that's why lots of folks don't like C. Personally, I love
it……guess it all depends on your point of view.