...
According to the C Standard, Section section 6.5 [ISO/IEC 9899:2011],
Except as specified later, side effects and value computations of subexpressions are unsequenced.
...
- The order in which the arguments to a function are evaluated (C Standard, Section section 6.5.2.2, "Function Calls")
- The order of evaluation of the operands in an assignment statement (C Standard, Section section 6.5.16, "Assignment Operators")
- The order in which any side effects occur among the initialization list expressions is unspecified. In particular, the evaluation order need not be the same as the order of subobject initialization (C Standard, Section section 6.7.9, "Initialization")
This recommendation is related to EXP30-C. Do not depend on order of evaluation between sequence points, but it focuses on behavior that is nonportable or potentially confusing.
...
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
Compass/ROSE |
|
| Could detect violations of this recommendation by searching for the following pattern:
| ||||||
| EVALUATION_ORDER | Can detect the specific instance where a statement contains multiple side effects on the same value with an undefined evaluation order because the statement may behave differently with different compiler flags or different compilers or platforms. | |||||||
| 35 D | Fully implemented. | |||||||
PRQA QA-C |
| 3226 | Partially implemented. |
A programmer could also violate the recommendation using dynamic memory passed to both functions, but that would be extremely difficult to detect using static analysis.
...
CERT C++ Secure Coding Standard | EXP10-CPP. Do not depend on the order of evaluation of subexpressions or the order in which side effects take place |
ISO/IEC TR 24772:2013 | Operator Precedence/Order of Evaluation [JCW] Side-effects and Order of Evaluation [SAM] |
MISRA - C:2012 | Rule 12.213.5 (required) |
Bibliography
[ISO/IEC 9899:2011] | Section 6.5, "Expressions" |
...