Synopsis: | Expressions shall not contain multiple side-effects due either to the same identifier being modified more than once, or due to the same identifier being modified and accessed. |
Language: | C |
Severity Level: | 2 |
Category: | EXPRESSIONS |
Description: |
For all but a few constructs in C, Standard C does not define the evaluation order even where there may be side-effects. Reliance on them can create problems which are very expensive to track down.
Example: Even something as simple as two function references in the same expression can lead to problems.x = i++ + a[i]; /* WRONG - 2 side effects x assigned and i changed */ x = i + a[i]; /* RIGHT */ i++; Example: x = f() + g(); /* CAUTION - if f and g both modify and access the same externally visible identifier, big problemsmay result. */ t = f(); x = t + g(); /* SAFE, but may lead to expressions becoming hard to understand. */ |