Re: INT_MIN and compiler diagnostic
- From: Beej Jorgensen <beej@xxxxxxx>
- Date: Wed, 28 Feb 2007 12:32:19 +0100 (CET)
<p_cricket_guy@xxxxxxxxxxx> wrote:
/tmp/x.c:7: warning: this decimal constant is unsigned only in ISO C90
I think it was addressed in this thread:
http://tinyurl.com/ytuxdv
# define INT_MIN (-INT_MAX - 1)
# define INT_MAX 2147483647
This produces the warning:
int y = -2147483648;
whereas this does not:
int y = (-2147483647 - 1);
(Interestingly, though, I guess I expected the preprocessor to calculate
the final answer before passing it to the compiler, and it doesn't.
And now, it doesn't even make sense that the preprocessor would do it.
I mean, the compiler has to do that kind of stuff anyway, right?
So why did I have it in the back of my mind that the preprocessor
sometimes did simple math? Some holdover from the olden days of not-so-
optimal compilers?)
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).
-Beej
.
- Follow-Ups:
- Re: INT_MIN and compiler diagnostic
- From: Keith Thompson
- Re: INT_MIN and compiler diagnostic
- From: CBFalconer
- Re: INT_MIN and compiler diagnostic
- Prev by Date: Re: INT_MIN and compiler diagnostic
- Next by Date: syntactically comprehensive test program
- Previous by thread: Re: INT_MIN and compiler diagnostic
- Next by thread: Re: INT_MIN and compiler diagnostic
- Index(es):
Relevant Pages
|