Common ansi violation, exemplified.

Alan Mycroft am at jenny
Mon Apr 18 21:13:22 AEST 1988


In article <1988Apr13.163235.420 at utzoo.uucp> henry at utzoo.uucp (Henry Spencer) writes:
>> 	#elif (1<<63) < 0
>> 	#define int_size_in_bits	64
>Furthermore, even
>ignoring that, there is another problem:  the result of shifting ***beyond***
>the available number of bits is implementation-defined (or undefined).
There is a related problem in lesser shifts in that the ANSI draft forbids
        1<<31   even when ints have 32 bits (overflow)
Note that
	1U<<31  has to be used instead.
Since overflow is undefined, the test
        if ((1<<31) < 0) may do exactly as it wishes.
When ints have 32 bits, I believe the public review 2nd draft *requires*
constant reducers to report a diagnostic for 1<<31 if they reduce it
(overflow during constant reduction to be reported).
They probably do not need to do so if they do not reduce it.
Hmm, wonder about the 'as if' rule here!!!



More information about the Comp.lang.c mailing list