Sun Studio 12: C User's Guide

4.6.1.3 Questionable Constructs

lint flags a miscellany of legal constructs that may not represent what the programmer intended. Examples:


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) ...

int fun()
{
    int a, b, x, y;
    (a = x) && (b == y);
}

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.