...
Code Block | ||
---|---|---|
| ||
int a = 2; int b = 2; int c = 2; // ... if ( a < b < c ) // condition #1,* misleading, likely bug */ // ... if ( a == b == c ) //* condition #2, misleading, likely bug */ |
Condition #1 The expression a < b < c
evaluates to true, rather than false as its author probably intended, and condition #2 the expression a == b == c
evaluates to false, rather than true as its author probably intended.
...
Code Block | ||
---|---|---|
| ||
if ( (a < b) && (b < c) ) //* clearer, and probably what was intended */ // ... if ( (a == b) && (a == c) ) //* ditto */ |
Automated Detection
The gcc option -Wparentheses
warns if a comparison like `x<=y<=z' appears. This warning is also enabled by -Wall
.
...