lint flags a miscellany of legal constructs that may not represent what the programmer intended. Examples:
An unsigned variable always has a nonnegative value. So the test:
unsigned x; if (x < 0) ... |
always fails. The test:
unsigned x; if (x > 0) ... |
is equivalent to:
if (x != 0) ... |
This may not be the intended action. lint flags questionable 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) ... |
lint flags expressions without side effects that are used in a context where side effects are expected—that is, where the expression may not represent what the programmer intends. It issues an additional warning whenever the equality operator is found where the assignment operator is expected—that is, where a side effect is expected:
int fun() { int a, b, x, y; (a = x) && (b == y); } |
lint cautions you to parenthesize expressions that mix both the logical and bitwise operators (specifically, &, |, ^, <<, >>), where misunderstanding of operator precedence may lead to incorrect results. Because the precedence of bitwise &, for example, falls below logical ==, the expression:
if (x & a == 0) ... |
is evaluated as:
if (x & (a == 0)) ... |
which is most likely not what you intended. Invoking lint with -h disables the diagnostic.