|
|
Some nonportable code is flagged by lint
in its default behavior, and a few more cases are diagnosed when lint
is invoked with -p and/or -Xc.
The latter tells lint to check
for constructs that do not conform to the ANSI C standard.
For the messages issued under -p and -Xc,
check
``Using lint''.
Examples:
char c;where EOF has the value -1, will always fail on machines where character variables take on nonnegative values. One of lint's -p checks will flag any comparison that implies a ``plain'' char may have a negative value. Note, however, that declaring c a signed char in the above example eliminates the diagnostic, not the problem. That's because getchar() must return all possible characters and a distinct EOF value, so a char cannot store its value. This example, which is perhaps the most common one arising from implementation-defined sign-extension, shows how a thoughtful application of lint's portability option can help you discover bugs not related to portability. In any case, declare c as an int.c = getchar(); if (c == EOF) . . .
short s; long l; s = l;lint flags all such assignments by default; the diagnostic can be suppressed by invoking the -a option. Bear in mind that you may be suppressing other diagnostics when you invoke lint with this or any other option. Check the list in ``Using lint'' for the options that suppress more than one diagnostic.
intbecause, on most machines, an int cannot start on an arbitrary byte boundary, whereas a char can. If you suppress the diagnostic by invoking lint with -h, you may be disabling other messages. You can eliminate the problem by using the generic pointer voidfun(y) char
y; { return(int
)y; }
.
int a[10];
main()
{
int i = 1;
a[i++] = i;
}
Note that in this example the value of a[1] may
be 1 if one compiler is used, 2 if another.
The bitwise logical operator & can also give
rise to this diagnostic when it is mistakenly
used in place of the logical operator &&:
if ((c = getchar()) != EOF & c != '0')