incorrect enum warning?
Bakul Shah
bakul at bitblocks.com
Thu May 1 15:31:49 PDT 2003
> > int main ()
> > {
> > printf("%d\n", (0x80000000 == INT_MIN));
> > return 0;
> > }
> >
> > ./a.out
> > 1
> >
> > Just pointing out that they do "==" each other, which is what was said.
>
> That is because the comparison is done in unsigned arithmetics due to
> the "usual arithmetic conversions". The negative int value INT_MIN is
> converted to unsigned int by adding UINT_MAX + 1 before the comparison
> is evaluated.
\begin{nitpicking}
0x80000000 is *not* an unsigned int, just a regular signed
int but outside the legal range. An unsigned int literal has
to have a U at the end. Since 0x80000000 > INT_MAX, all bets
are off. The result is unspecified and happens to be 1 on a
2s complement 32 bit machine but can be 0 or anything else on
a ones complement machine or where int is not 32 bits wide.
\end{nitpicking}
More information about the freebsd-hackers
mailing list