Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: C wish list Date: Wed, 20 Mar 2019 17:52:01 -0700 Organization: None to speak of Lines: 34 Message-ID: References: <11b51bdf-7847-40fc-bdf5-b3777f41b4da@googlegroups.com> <87bm25yub0.fsf@bsb.me.uk> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: reader02.eternal-september.org; posting-host="9515313518a1e23526d751bd086ff0bd"; logging-data="16086"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TcY7EQPNvVaFBQi8Tp6FN" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:zs/z+G+Dg8J9YDSMGeR8jXbi53I= sha1:lhNHJVEyocbTvAhXl17LQlN0s+Y= Xref: csiph.com comp.lang.c:142160 Ben Bacarisse writes: > Keith Thompson writes: [...] >> The proposed wording is: >> >> The value of E1 << E2 is E1 left-shifted E2 bit positions; vacated >> bits are zero-filled. The value of the result is E1×2^E2, reduced >> modulo 2^N, where N is the number of value bits in the result >> type. > > Doesn't that make 1 << 31 yield 0 for 32-bit signed int? The results > would also be rather "unexpected" for smaller shifts of negative numbers > (e.g. -1 << 0 would be 2147483647 AKA 0x7fffffff). > > Yes, it does. I made some lazy and incorrect assumptions. I think the intent is that the << operator should operate on bits in the same way for signed and unsigned types. For 32-bit unsigned int, 1U<<31 yields 2147483648. That bit pattern represents -2147483648 in 32-bit signed int, but the wording I quoted would reduce that modulo 2147483648, yielding 0. Using gcc on my system, 1<<31 yields -2147483648 (though the behavior is undefined). Either the proposal is inconsistent (perhaps just in this case?) or I'm misreading it. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Will write code for food. void Void(void) { Void(); } /* The recursive call of the void */