OK, here it is: you are wrong.
I'm not sure if it's been spelled out emphatically enough why this is undefined, and how you can tell if an expression leads to undefined behavior in the C language.
Here's my shot at it:
C does not specify the order in which the operands of an operator are evaluated. (The exceptions are &&, ||, ?:, and ",".)
It was previously stated that "order of evaluation" has
nothing to do with operator precedence. This is the point that lots of people have trouble absorbing, so I'll repeat it. "Order of evaluation" has
nothing to do with operator precedence.
So, given the expression
Code:
x = (f() + g()) * h();
It may happen that f() is evaluated first or it may happen that g() is evaluated first, or it may happen that h() is evaluated first. If either f() or g() or h() changes the value of a variable that one (or both of) the others depend(s) on, the behavior is undefined.
If you have
any expression that whose behavior or value depends on the order of evaluation of its terms then the behavior is undefined (except for the operators listed above).
Also note that if you have the statement
The functions a(), b(), and c() may be evaluated by a given compiler in any order.
A concrete example:
Code:
printf("%d %d %d", i++, i, ++i);
If you run this through 10 compilers, or 20, or 30 and they all give the result that indicates that c() is evaluated, then b(), then a(), that still doesn't make the behavior "defined" according to the C standard. If two compilers give different results, it doesn't mean that one is "right" and the other are "wrong". There is no "wrong" compiler behavior here. The result is not required to be any particular thing.
Regards,
Dave