Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The order of evaluation of subexpressions and the order in which side effects take place are frequently defined as unspecified behavior by C99. Counter-intuitively, unspecified behavior is where the standard provides two or more possibilities and imposes no further requirements on which is chosen in any instance. Consequently, unspecified behavior can be a portability issue, as different implementations can make different choices. If dynamic scheduling is used, however, there may not be a fixed-code execution sequence over the life of a process. Operations that can be executed in different orderings may in fact be executed in a different order.

...

This recommendation is related to guideline rule EXP30-C. Do not depend on order of evaluation between sequence points, but this recommendation focuses on behavior that is nonportable or potentially confusing.

...

Search for vulnerabilities resulting from the violation of this rule on the CERT website.

Related Guidelines

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

Bibliography

unmigrated-wiki-markup

\[[ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Section 6.5, "Expressions," Section 6.5.16, "Assignment operators," Section 6.5.2.2, "Function calls," and Section 6.7.8, "Initialization" \[[

ISO/IEC PDTR 24772|AA. Bibliography#ISO/IEC PDTR 24772]\] "JCW Operator precedence/Order of Evaluation" and "SAM Side-effects and Order of Evaluation" \[[MISRA 2004|AA. Bibliography#MISRA 04]\] Rule

MISRA Rule 12.2

Bibliography

...

      03. Expressions (EXP)      EXP11-C. Do not apply operators expecting one type to data of an incompatible type