Synopsis: | Side effects shall not be relied upon between successive sequence points. |
Language: | C |
Severity Level: | 3 |
Category: | Conceptual Models |
Description: |
Justification For a few constructs in C, the standard does not define the evaluation order when there is more than one side-effect in it. Reliance on them can create problems which are very difficult to track down. Note that this even may occur with the same compiler but a different set of compiler options. Example 1 x = i++ + a[i]; /* WRONG */ y = f() + g() /* WRONG */ Example 2 x = i + a[i]; /* RIGHT */ i++; Example 3 y = f(); /* RIGHT */ y += g(); Note It is best practice not to have two function calls in one statement, but usage of functions with no (or neglectable) side effects can be used. double d = sin(x) + fabs(x); /* RIGHT */ |