Path: utzoo!mnetor!uunet!mcvax!ukc!cam-cl!am From: am@jenny (Alan Mycroft) Newsgroups: comp.lang.c Subject: Common ansi violation, exemplified. Message-ID: <122@gannet.cl.cam.ac.uk> Date: 18 Apr 88 11:13:22 GMT References: <10949@mimsy.UUCP> <1525@dataio.Data-IO.COM> <1988Apr13.163235.420@utzoo.uucp> Sender: news@cl.cam.ac.uk Reply-To: am@cl.cam.ac.uk (Alan Mycroft) Organization: U of Cambridge Comp Lab, UK Lines: 17 Summary: 1<<31 is illegal In article <1988Apr13.163235.420@utzoo.uucp> henry@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!!!