Is #define THING -10 completely safe?
Paul de Bra
debra at svin02.info.win.tue.nl
Tue Jan 29 22:15:44 AEST 1991
In article <33 at christmas.UUCP> rtm at island.COM (Richard Minner) writes:
>In article <1991Jan23.015757.22220 at portia.Stanford.EDU> fangchin at portia.Stanford.EDU (Chin Fang) writes:
>>... from my /usr/include/limits.h
>>#define INT_MIN -2147483648 /* min decimal value of an "int" */
As James Clark reminded me a long time ago,
-2147483648 is a (constant) expression, not evaluated by the preprocessor
but by the compiler. This has 2 implications:
1) as people have said before, the replacement is purely textual, so the
unary minus can be misused as a binary minus when writing something
like 5 INT_MIN
2) this define is not supposed to work at all if 2147483648 is not a legal
positive integer. (on most machines it isn't)
if INT_MAX is 2147483647 then INT_MIN should not be written as
-2147483648 but as (-2147483647-1)
so your limits.h is at fault, and some compilers (including gcc)
will not treat your INT_MIN as a large negative number, because
of integral promotion. (2147483648 is promoted to unsigned because
it is too large for a signed int)
Paul.
(debra at win.tue.nl, debra at research.att.com)
More information about the Comp.lang.c
mailing list