...
The order in which operands in an expression are evaluated is unspecified in C++. The only guarantee is that they will all be completely evaluated at the next sequence point. According to ISO/IEC 14882-2003:
The following are the sequence points defined by ISO/IEC 14882-2003:
- at the completion of evaluation of each full-expression;
- after the evaluation of all function arguments (if any) and before execution of any expressions or statements in the function body;
- after the copying of a returned value and before the execution of any expressions outside the function;
- after the evaluation of the first operand of the following operators:
&&
(logicalAND
);||
(logicalOR
); ? (conditional); , (comma, but see the note immediately following); - after the initialization of each base and member in a class.
Note that not all instances of a comma in C++ code denote a usage of the comma operator. For example, the comma between arguments in a function call is NOT the comma operator.
According to ISO/IEC 14882-2003:
Between the previous and next sequence point a scalar object shall have its stored value modified at most once by the evaluation of an expression. Furthermore, the prior value shall be accessed only to determine the value to be stored.
...
Wiki Markup |
---|
\[[ISO/IEC 14882-2003|AA. References#ISOBibliography#ISO/IEC 14882-2003]\] Sections 1.9 Program execution, 5 Expressions, 12.6.2 Initializing bases and members. \[[ISO/IEC 14882-2003|AA. References#ISOBibliography#ISO/IEC 14882-2003]\] Sections 1.9 Program execution, 5 Expressions, 12.6.2 Initializing bases and members. \[[Summit 05|AA. References#SummitBibliography#Summit 05]\] Questions 3.1, 3.2, 3.3, 3.3b, 3.7, 3.8, 3.9, 3.10a, 3.10b, 3.11. \[[Lockheed Martin 05|AA. References#LockheedBibliography#Lockheed Martin 05]\] AV Rule 204.1 The value of an expression shall be the same under any order of evaluation that the standard permits. \[[Saks 07|AA. References#SaksBibliography#Saks 07]\] |
...
EXP17-CPP. Treat relational and equality operators as if they were nonassociative 03. Expressions (EXP) EXP31-CPP. Avoid side effects in assertions