Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Ike Naar <ike@faeroes.freeshell.org> |
|---|---|
| Newsgroups | comp.std.c |
| Subject | Re: Why is shifting too far undefined behvaior? |
| Date | 2021-09-21 11:33 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <slrnskjgmp.3ce.ike@faeroes.freeshell.org> (permalink) |
| References | <siceh0$1lm$1@solani.org> |
On 2021-09-21, Philipp Klaus Krause <pkk@spth.de> wrote: > Looking at the C23 draft N2596, section J.2 (but this AFAIK has been the > same forever), we see that there is undefined behavior, when "An > expression is shifted by a negative number or by an amount greater than > or equal to the width of the promoted expression (6.5.7)." or "An > expression having signed promoted type is left-shifted and either the > value of the expression is negative or the result of shifting would not > be representable in the promoted type (6.5.7)." > > Does anyone know why this was made undefined (as opposed to yielding an > unspecified value)? The C99 rationale doesn't mention anything. > > The only idea that comes to my mind is that it would be to allow > implementations to trap at runtime when shifting too far, which might > help with debugging. Another thing that comes to mind is that on a machine with N-bit wordsize, the machine instruction for shifting might only use log2(N) bits to specify the number of places to shift. Shifting N places or more would not be possible on such hardware (at least, not with a single shift instruction).
Back to comp.std.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why is shifting too far undefined behvaior? Philipp Klaus Krause <pkk@spth.de> - 2021-09-21 13:09 +0200
Re: Why is shifting too far undefined behvaior? Ike Naar <ike@faeroes.freeshell.org> - 2021-09-21 11:33 +0000
Re: Why is shifting too far undefined behvaior? Richard Kettlewell <invalid@invalid.invalid> - 2021-09-21 12:47 +0100
Re: Why is shifting too far undefined behvaior? Richard Damon <Richard@Damon-Family.org> - 2021-09-21 08:29 -0400
Re: Why is shifting too far undefined behvaior? Vincent Lefevre <vincent-news@vinc17.net> - 2021-09-22 01:17 +0000
Re: Why is shifting too far undefined behvaior? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-21 19:05 -0700
Re: Why is shifting too far undefined behvaior? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-09-22 00:02 -0400
Re: Why is shifting too far undefined behvaior? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-21 21:12 -0700
Re: Why is shifting too far undefined behvaior? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-09-22 09:42 -0400
Re: Why is shifting too far undefined behvaior? Richard Damon <Richard@Damon-Family.org> - 2021-09-22 07:08 -0400
Re: Why is shifting too far undefined behvaior? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-09-22 09:42 -0400
Re: Why is shifting too far undefined behvaior? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-09-23 12:18 -0400
Re: Why is shifting too far undefined behvaior? Vincent Lefevre <vincent-news@vinc17.net> - 2021-09-23 11:10 +0000
Re: Why is shifting too far undefined behvaior? James Kuyper <jameskuyper@alumni.caltech.edu> - 2021-09-23 12:22 -0400
Re: Why is shifting too far undefined behvaior? Vincent Lefevre <vincent-news@vinc17.net> - 2021-09-23 11:08 +0000
Re: Why is shifting too far undefined behvaior? Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2021-09-21 11:01 -0700
Re: Why is shifting too far undefined behvaior? Philipp Klaus Krause <pkk@spth.de> - 2021-09-21 20:12 +0200
Re: Why is shifting too far undefined behvaior? Vincent Lefevre <vincent-news@vinc17.net> - 2021-09-22 01:13 +0000
Re: Why is shifting too far undefined behvaior? David Brown <david.brown@hesbynett.no> - 2021-09-22 14:25 +0200
Re: Why is shifting too far undefined behvaior? Vincent Lefevre <vincent-news@vinc17.net> - 2021-09-23 11:17 +0000
Re: Why is shifting too far undefined behvaior? Tim Rentsch <txr@shamko.com> - 2021-10-09 04:27 -0700
csiph-web