...
The following are the sequence points describeddefined by C99:
- 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 ,.
- The end of a full declarator: declarators;
- The end of a full expression: an initializer; the expression in an expression statement; 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 library function returns (7.1.4).
- After the actions associated with each formatted input/output function conversion specifier.
- Immediately before and immediately after each call to a comparison function, and also between any call to a comparison function and any movement of the objects passed as arguments to that call.
Between the previous and next sequence point an object can only have its stored value modified at most once by the evaluation of an expression. Additionally, the prior value
can be read only to determine the value to be stored.
Non-compliant Code Example
...
Code Block |
---|
a = i + b[i+1]; ++i; |
Non-compliant Code Example2
There is no ordering of subexpressions implied by the assignment operator, so the behavior of the following statements is undefined:
Code Block |
---|
i = ++i + 1;
a[i++] = i;
|
Compliant Solution
The following statements are allowed by the standard:
Code Block |
---|
i = i + 1;
a[i] = i;
|
References
- ISO/IEC 9899-1999 Section 5.1.2.3 Program execution
- ISO/IEC 9899-1999 Section 6.5 Expressions
- ISO/IEC 9899-1999 Annex C Sequence points
- comp.lang.c FAQ list - Question 3.1