Evaluation of an expression may produce side effects. At specific points during execution, known as sequence points, all side effects of previous evaluations have completed, and no side effects of subsequent evaluations have yet taken place.
According to C99, Section 6.5 \[ [ISO/IEC 9899:1999|AA. Bibliography#ISO/IEC 9899-1999]\] Wiki Markup
Between the previous and next sequence point an object can only have its stored value modified once by the evaluation of an expression. Additionally, the prior value can be read only to determine the value to be stored.
...
This requirement must be met for each allowable ordering of the subexpressions of a full expression; otherwise, the behavior is undefined.
The following sequence points are defined in Annex C, Sequence Points, of C99 \[ [ISO/IEC 9899-1999|AA. Bibliography#ISO/IEC 9899-1999]\]: Wiki Markup
- 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:
,
- logical AND:
- 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
orswitch
) - the controlling expression of a
while
ordo
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.
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
---|---|---|---|---|---|
EXP30-C | medium | probable | medium | P8 | L2 |
Automated Detection
Tool | Version | Checker | Description | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
|
| ||||||||||||
|
|
|
| ||||||||||||
|
|
|
| ||||||||||||
|
|
|
| ||||||||||||
|
|
|
|
...
MISRA Rule 12.1
Bibliography
...
\[[Summit 2005|AA. Bibliography#Summit 05]\] Questions 3.1, 3.2, 3.3, 3.3b, 3.7, 3.8, 3.9, 3.10a, 3.10b, and 3.11
\[
[Saks 2007|AA. Bibliography#Saks 07]\]
...
EXP21-C. Place constants on the left of equality comparisons EXP30-C. Do not depend on order of evaluation between sequence points EXP30-C. Do not depend on order of evaluation between sequence points