|
|
lint flags a number of valid constructs that may not represent what the programmer intended. Examples:
unsigned x; if (x < 0) . . .will always fail. Whereas the test
unsigned x; if (x > 0) . . .is equivalent to
if (x != 0) . . .which may not be the intended action. lint flags suspicious comparisons of unsigned variables with negative constants or 0. To compare an unsigned variable to the bit pattern of a negative number, cast it to unsigned:
if (u == (unsigned) -1) . . .Or use the U suffix:
if (u == -1U) . . .
int fun() { int a, b, x, y; (a = x) && (b == y); }
if (x & a == 0) . . .will be evaluated as
if (x & (a == 0)) . . .which is most likely not what you intended. Invoking lint with -h disables the diagnostic.