|
|
In the following code, assume ints are 16 bits.
int f(void)
{
int i = 0;
return i > 0xffff;
}
Because the hexadecimal constant's type is either
int (with a value of -1 on a two's-complement machine)
or an unsigned int
(with a value of 65535),
the comparison will be true on a non-ANSI C compiler
(-Xt and -Xk modes),
and false on an ANSI C compiler
(-Xa, -Xc, and -Xm modes).
An appropriate cast clarifies the code and silences the ANSI C compiler:
Non-ANSI C behavior:
i > (int)0xffffANSI C behavior:
i > (unsigned int)0xffff
or
i > 0xffffU
(The U suffix character is a new feature of ANSI C
and will probably produce an error message with
older compilers.)