Is #define THING -10 completely safe?

Luc Rooijakkers lwj at cs.kun.nl
Tue Jan 29 21:01:51 AEST 1991


In <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.

This may have been the intention of the comittee. However, I cannot find
such a guarantee:

	2.2.4.2 Sizes of Integral Types <limits.h>

	The values given below shall be replaced by constant expressions
	suitable for use in #if preprocessing directives.
	
Now, an expression like -2147483648 certainly satisfies the above
constraints.

>>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.

Right. As has been pointed out already, however, there are also contexts
that can cause trouble where the standard requires it, e.g.

	INT_MIN[p]

which expands to

	-2147483648[p]

which is equivalent to

	-(2147483648[p])

Thus, I would conclude that INT_MIN cannot be used in this way in a
strictly conforming program. Instead, 

	(INT_MIN)[p]
	
would have to be used.

(This is an obscure corner of the language, I agree.)

--
Luc Rooijakkers                                 Internet: lwj at cs.kun.nl
Faculty of Mathematics and Computer Science     UUCP: uunet!cs.kun.nl!lwj
University of Nijmegen, the Netherlands         tel. +3180652271



More information about the Comp.lang.c mailing list