Sequence point

In C and C++, a sequence point defines any point in a computer program's execution at which it is guaranteed that all side effects of previous evaluations will have been performed, and no side effects from subsequent evaluations have yet been performed. They are a core concept for determining the validity of and, if valid, the possible results of expressions. Adding more sequence points is sometimes necessary to make an expression defined and to ensure a single valid order of evaluation.

With C11 and C++11, usage of the term sequence point has been replaced by sequencing. There are three possibilities:[1][2][3]

  1. An expression's evaluation can be sequenced before that of another expression, or equivalently the other expression's evaluation is sequenced after that of the first.
  2. The expressions' evaluation is indeterminately sequenced, meaning one is sequenced before the other, but which is unspecified.
  3. The expressions' evaluation is unsequenced.

The execution of unsequenced evaluations can overlap, leading to potentially catastrophic undefined behavior if they share state. This situation can arise in parallel computations, causing race conditions, but undefined behavior can also result in single-threaded situations. For example, a[i] = i++; (where a is an array and i is an integer) has undefined behavior.

  1. ^ "ISO/IEC 14882:2011". Retrieved 2012-07-04.
  2. ^ "A finer-grained alternative to sequence points (revised) (WG21/N2239 J16/07-0099)". Retrieved 2012-07-05.
  3. ^ "Order of evaluation". Retrieved 2015-10-14.