Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | David Brown <david.brown@hesbynett.no> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Negative shift counts |
| Date | 2015-04-21 12:22 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <mh58be$b74$2@dont-email.me> (permalink) |
| References | <mh55g0$20q$1@dont-email.me> |
On 21/04/15 11:33, Noob wrote: > Hello, > > I am aware that negative shift counts have undefined behavior. > > int i = 40 << -2; // UB > > It seems to me that a natural way to extend shift counts to > negative values would be to just flip the shift direction. > > The above statement would behave "as if" we'd written > > int i = 40 >> 2; > > > I suppose negative shift counts were unsupported in the original > language definition (?) in the 70s and remained unsupported in the > first edition of K&R C? Perhaps this was done to save space when > RAM was tight, and such a "feature" was not considered to bring > any value? > > Then ANSI saw no benefit to discuss defining the behavior during > the standardization process in the 80s? Because no implementation > offered this as an extension? > > I'm perplexed, because it seems to be a trivial extension, with > low complexity, for a small gain in expressiveness. > > Do you see perhaps other ways to define the behavior of negative > shift counts that would be at odds with the one proposed above? > > Regards. The conversion between shift directions is trivial when the shift count is constant - much less so when it is variable.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Negative shift counts Noob <root@127.0.0.1> - 2015-04-21 11:33 +0200
Re: Negative shift counts David Brown <david.brown@hesbynett.no> - 2015-04-21 12:22 +0200
Re: Negative shift counts Noob <root@127.0.0.1> - 2015-04-21 13:12 +0200
Re: Negative shift counts Ben Bacarisse <ben.usenet@bsb.me.uk> - 2015-04-21 12:02 +0100
Re: Negative shift counts glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2015-04-29 20:08 +0000
csiph-web