order of evaluation of operands order of evaluation of operands c c

order of evaluation of operands


In C++, for user-defined types a + b is a function call, and the standard says:

§5.2.2.8 - [...] The order of evaluation of function arguments is unspecified. [...]

For normal operators, the standard says:

§5.4 - Except where noted, the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is unspecified. [...]

These haven't been changed for C++11. However, the wording changes in the second one to say that the order is "unsequenced" rather than unspecified, but it is essentially the same.

I don't have a copy of the C standard, but I imagine that it is the same there as well.


It is Unspecified.

Reference - C++03 Standard:

Section 5: Expressions, Para 4:

except where noted [e.g. special rules for && and ||], the order of evaluation of operands of individual operators and subexpressions of individual expressions, and the order in which side effects take place, is Unspecified.


C++0x FDIS section 1.9 "Program Execution" §15 is similar to the corresponding paragraph in C++03, just reworded to accommodate the conceptual change from "sequence points" to "being sequenced":

Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced.