lint flags a number of valid constructs
that may not represent what the programmer intended.
An unsigned variable always has a nonnegative value.
So the test
if (x < 0) . . .
will always fail.
Whereas the test
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) . . .
lint flags expressions without side effects
that are used in a context where side effects are expected,
where the expression may not represent what the programmer intended.
It issues an additional
warning whenever the equality operator
is found where the assignment operator was expected, in other words, where a side effect was expected:
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) . . .
will be evaluated as
if (x & (a == 0)) . . .
which is most likely not what you intended.
Invoking lint with -h disables the diagnostic.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003