Download dir - Oracle Documentation
Transcript
■
A cast of a pointer to one object type to a pointer to an object type with stricter
alignment requirements may not be portable. lint flags:
int *fun(y)
char *y;
{
return(int *)y;
}
because, on most machines, an int cannot start on an arbitrary byte boundary,
whereas a char can. You can suppress the diagnostic by invoking lint with –h,
although, again, you may be disabling other messages. Better still, eliminate the
problem by using the generic pointer void *.
■
ANSI/ISO C leaves the order of evaluation of complicated expressions undefined.
That is, when function calls, nested assignment statements, or the increment and
decrement operators cause side effects when a variable is changed as a
by-product of the evaluation of an expression, the order in which the side effects
take place is highly machine-dependent. By default, lint flags any variable
changed by a side effect and used elsewhere in the same expression:
int a[10];
main()
{
int i = 1;
a[i++] = i;
}
In this example, the value of a[1] may be 1 if one compiler is used, 2 if another.
The bitwise logical operator & can give rise to this diagnostic when it is
mistakenly used in place of the logical operator &&:
if ((c = getchar()) != EOF & c != '0')
Questionable Constructs
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) ...
180
C User’s Guide • May 2000