Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: Is this code considered to transgress the signed overflow purism? Date: Sun, 30 Apr 2017 14:11:53 -0700 Organization: None to speak of Lines: 24 Message-ID: References: <11ea6682-cdee-4513-97c2-6c90b585716a@googlegroups.com> <307ebff5-b74f-46ab-beb7-7e2e4ff494fb@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: mx02.eternal-september.org; posting-host="518c2254bac820b1cb24a1d9d6a93e31"; logging-data="26684"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Y43cQAnXX6rVg3l5Nviy+" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) Cancel-Lock: sha1:3hQdWJBfr45khvCAWhgWBlUyiQE= sha1:0RhuD/UIQI+VDEbZWNMfi8elA7o= Xref: csiph.com comp.lang.c:108808 Tim Rentsch writes: > Keith Thompson writes: >> The authors of the C89 standard deliberately stated that a left >> shift on a negative value has undefined behavior. [...] > > Did you mean the C99 standard? In C89/C90 left shifting > a negative value is implementation-defined behavior, not > undefined behavior. No, I *meant* C89, but I was mistaken. However, C89/C90 doesn't say that a left shift of a negative value has implementation-defined behavior, at least not explicitly. (It does say so for right shift.) It defines the behavior in terms of bit positions, not values. It then clarifies the semantics in terms of values when E1 has an unsigned type, but not when E1 has a signed type. I suppose you could say that the result depends on the representation, which is implementation-defined. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"