Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 01 May 2003 15:31:40 -0700
From:      Bakul Shah <bakul@bitblocks.com>
To:        Stefan Farfeleder <stefan@fafoe.dyndns.org>
Cc:        hackers@freebsd.org
Subject:   Re: incorrect enum warning? 
Message-ID:  <200305012231.h41MVePF062201@bitblocks.com>
In-Reply-To: Your message of "Fri, 02 May 2003 00:16:32 %2B0200." <20030501221631.GB546@wombat.fafoe> 

next in thread | previous in thread | raw e-mail | index | archive | help
> > 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}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200305012231.h41MVePF062201>