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.

Documentation for C11 and C++11 stopped using the term "sequence point" and now uses alternative terms:

  1. An expression's evaluation can be "sequenced before" the evaluation of another expression. (Equivalently, the other expression's evaluation can be "sequenced after" that of the first.)
  2. The expressions' evaluation is "indeterminately sequenced", meaning that one is "sequenced before" the other, but which is unspecified.
  3. The expressions' evaluation is "unsequenced", meaning the operations in each expression may be interleaved.

The execution of unsequenced evaluations can overlap, leading to potentially catastrophic undefined behavior if they share state. This situation can arise in parallel computing, 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.