TICS Coding Standard Viewer 
TIOBE Software Quality Framework
Print-friendly version
©TIOBE Software www.tiobe.com
 
TIOBE - C Coding Standard
Search

SR:  9.4#1Checked automatically with code checker

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 */