...
are not allowed because they modify the same value twice.
Non-Compliant Code Example
In this example, the order of evaluation of the operands to + is undefined.
...
As a result, programs cannot safely rely on the order of evaluatoin of operands between sequence pionts.
Compliant Solution
These examples are independend on the order of evaluation of the operands and can only be interpreted in one way.
...
Code Block |
---|
a = i + b[i+1]; ++i; |
Non-Compliant Code Example
There is no ordering of subexpressions implied by the assignment operator, so the behavior of these statements is undefined.
Code Block |
---|
i = ++i + 1; a[i++] = i; |
Compliant Solution
These statements are allowed by the standard.
Code Block |
---|
i = i + 1; a[i] = i; |
Non-Compliant Code Example
The order of evaluation of arguments to a function is undefined.
Code Block |
---|
func(i++, i++); |
Compliant Solution
This solution is appropriate when the programmer intends for both arguments to func()
to be equivalent.
...
Code Block |
---|
j = i; j++; func(i, j); |
Priority: P8 Level: L2
Component | Value |
---|---|
Severity | 2 (medium) |
Likelihood | 2 (probable) |
Remediation cost | 2 (medium) |
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
- Summit 05 Questions 3.1, 3.2, 3.3, 3.3b, 3.7, 3.8, 3.9, 3.10a, 3.10b, 3.11