...
Code Block | ||
---|---|---|
| ||
int a = 2; int b = 2; int c = 2; //* ... */ if (a < b < c) /* misleading, likely bug */ //* ... */ if (a == b == c) /* misleading, likely bug */ |
...
Code Block | ||
---|---|---|
| ||
if ( (a < b) && (b < c) ) /* clearer, and probably what was intended */ //* ... */ if ( (a == b) && (a == c) ) /* ditto */ |
Automated Detection
The gcc GCC option -Wparentheses
warns if a comparison like `x<x<=y<=z
' appears. This warning is also enabled by -Wall
.
...