In expression
a = a-- + a--;
you have many subexpressions that need to be evaluated before the entire expression is evaluated.
a = a-- + a--; ^^^ <= sub-expression 2 ^^^ <= sub-expression 1
What is the value of subexpression 1? This is the current value of object a .
What is the value of a ?
If subexpression 2 has already been evaluated, the value of the object a is 9, otherwise it is 10.
The same goes for subexpression 2. Its value can be 9 or 10, depending on whether subexpression 1 has already been evaluated.
The C compiler (I don't know about Java) is free to evaluate subexpressions in any order
So, let's say the compiler decided to leave -- for the last
a = 10 + 10; a--; a--;
but in the next compilation the compiler did -- in front
/* value of sub-expression 1 is 10 */ /* value of sub-expression 2 is 9 */ a = 10 + 9; /* a = 9 + 10; */
or he can even save one of a-- and use this for the final value of a
a = 10 + ???; a = 18???; a = 19???; a = 9
Or, when you invoked undefined behavior, it could just replace your statement with any of the following
- a = 42;
- / * * /
- fprintf (stderr, "BANG!");
- system ("format C:");
- for (p = 0; p <MEMORY_SIZE; p ++) * p = 0;
- etc.
source share