Synopsis: | Controlling expressions shall not contain assignments. |
Language: | C |
Severity Level: | 2 |
Category: | STATEMENTS |
Description: |
Isolating side-effects in expression statements helps the reader by making changes in state explicit, separating them from tests on that state. Implicit actions on behalf of an implementation are to be avoided for the sake of clarity. Modern compilers will optimise a comparison against zero in any case, defeating any arguments of efficiency.
Example: if ( a = 1 ) /* WRONG - unexpected behaviour */ if ( a == 1 ) /* RIGHT */ if ( (fp = get_file()) != NULL ) /* WRONG - confusing */ |