Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Enumerated C99 sequence points.

...

This requirement must be met for each allowable ordering of the subexpressions of a full expression; otherwise the behavior is undefined.

Wiki Markup
The following sequence points are defined in Annex C, Sequence Points, of C99 \[[ISO/IEC 9899-1999|AA. References#ISO/IEC 9899-1999]\]:

  • The call to a function, after the arguments have been evaluated.
  • The end of the first operand of the following operators:
    • logical AND: &&
    • logical OR: ||
    • conditional: ?
    • comma operator: ,
  • The end of a full declarator.
  • The end of a full expression:
    • an initializer
    • the expression in an expression statement (that is, at the semicolon)
    • the controlling expression of a selection statement (if or switch)
    • the controlling expression of a while or do statement
    • each of the expressions of a for statement
    • the expression in a return statement.
  • Immediately before a C standard library function returns.
  • After the actions associated with each formatted input/output function conversion specifier.
  • Immediately before and immediately after each call to a comparison function, by a standard searching or sorting function, and between any call to a comparison function and any movement of the objects passed as arguments to that call.

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 a sequence point.

This rule means that statements such as

Code Block
bgColor#ccccff
i = i + 1;
a[i] = i;

are allowedhave well-defined behavior, while statements like

Code Block
bgColor#FFcccc
/* i is modified twice between sequence points */
i = ++i + 1;  

/* i is read other than to determine the value to be stored */
a[i++] = i;   

are do not.

Noncompliant Code Example

...