glitch on Mar 15

Indeed. It's an undefined behavior.



C and C++ do not specify when the post-increment occurs within the statement, only that it is guaranteed to occur by the end token (i.e., ;) -- whether immediately before (or after) use, at the beginning (or end) of the statement, or at some point in between is not specified. For this reason, referencing a variable more than once in a statement where the post-increment operator is used results in undefined behavior. The same code may produce different results on different compilers, different architectures, or even the same compiler with different optimization settings.



So,

0, 0

0, 0

could also have been a result.



Although, for the original poster, to elaborate on the specific behavior of the initial post

1, 0

0, 1

some more, suppose we have m = 0; printf("(m++, m, m++): %d, %d, %d

", m++, m, m++);



(m++, m, m++) gave me 1, 2, 0 (with gcc version 4.0.1 Apple Inc. build 5488), which illustrates going on with that initial post.



The post-increment operators are evaluated first and from right to left, so the "m++" in the third parameter is done first (returning 0 and incremeting m to 1). The "m++" in the first parameter is done next, since it's the next post-increment operator to do (evaluating from right to left). The first parameter returns 1 and increments m to 2. This concludes the evaluation of the post-increment operators in the statement. Now, proceeding from right to left, the rest is done. So, finally, the "m" in the second parameter is evaluated as 2 (0 incremented to 1, which was then incremented to 2).

