Is #define THING -10 completely safe?
Nathan Sidwell
nathan at elberton.inmos.co.uk
Thu Jan 31 23:59:10 AEST 1991
In article <14998 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>In article <33 at christmas.UUCP> rtm at island.COM (Richard Minner) writes:
>>Something I've been curious about, should the above be
>>#define INT_MIN (-2147483648)
>
>Yes.
>
>>The precedence rules seem to imply that ()'s aren't needed
>>with a negative integer constant.
>
>There are contexts that could cause trouble, e.g. "x-INT_MIN"
>or "x=INT_MIN". While the C standard requires that these work
>as expected, many older C implementations will misinterpret
>these.
Well gcc -ansi doesn't,
source is
#define NUM -10
main()
{
int x;
x = x-NUM;
x = 1/**/2;
}
preprocessor output is
main()
{
int x;
x = x--10;
x = 1 2;
}
which fails, note that it is partly correct as
the /**/ has been reduced to a space. This is gcc 1.36, has it been
fixed in later versions?
Nathan Sidwell, INMOS Ltd, UK JANET: nathan at uk.co.inmos
Generic disclaimer applies UUCP: ukc!inmos!nathan
This space unintentionally filled INTERNET: nathan at inmos.com
More information about the Comp.lang.c
mailing list