Re: INT_MIN and compiler diagnostic
- From: CBFalconer <cbfalconer@xxxxxxxxx>
- Date: Wed, 28 Feb 2007 09:42:03 -0500
Beej Jorgensen wrote:
.... snip ...
.... snip ...
This produces the warning:
int y = -2147483648;
whereas this does not:
int y = (-2147483647 - 1);
Finally,
int y = -0x80000000;
does not produce a warning, though it is the same as -2147483648.
Apparently the rules are different for hex constants than they are
for decimal constants (c99 6.4.4.1p5).
In the first case you are negating the int 2147483648, which has
already overflowed and caused un/implementation defined behaviour.
In the second, you are negating the unsigned int 0x80000000, which
follows the rules for unsigned ints, and does not overflow.
--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
.
- References:
- Re: INT_MIN and compiler diagnostic
- From: Beej Jorgensen
- Re: INT_MIN and compiler diagnostic
- Prev by Date: Re: could you help me about this problem?
- Next by Date: Re: INT_MIN and compiler diagnostic
- Previous by thread: Re: INT_MIN and compiler diagnostic
- Next by thread: Re: INT_MIN and compiler diagnostic
- Index(es):
Relevant Pages
|