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: C++ forcing unnecessary changes to C? |
| Date | 2016-11-18 16:55 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <o0n889$psm$1@dont-email.me> (permalink) |
| References | <o0mseq$e7o$1@dont-email.me> <o0n2fs$reu$1@solani.org> <22e1d500-d9ec-489b-aa34-604e0923020e@googlegroups.com> |
On 18/11/16 16:15, supercat@casperkitty.com wrote: > On Friday, November 18, 2016 at 8:16:36 AM UTC-6, Philipp Klaus Krause wrote: >> From my experience, C++ does not force any changes on C, unnecessary or >> otherwise. > > From what I can tell, essentially all compilers for commonplace platforms > used to regard x<<y as yielding an Unspecified choice between x<<(y % wordsize) > and (x<<(y-1))<<1, and likewise for right-shifts. The idiomatic way to write > a rotate left was (x<<y)|(x>>(wordsize-y)); because that was the most natural > way to write that pattern, compilers could easily look for that exact pattern > and substitute a rotate-left instruction. There was no "idiomatic way" to write rotate operations, because rotate operations are not common enough to warrant idioms. A compiler may or may not defined the behaviour of shifts outside the ranges given in the standard. Someone needing a shift in their code may write correct portable code, or correct implementation-dependent code, or code that just happens to work without any guarantees. I think it is this later choice that you think of as "idiomatic", and believe that because someone might have written this, compilers should be obliged to implement it. > > C++ *requires* that an exact shift by the word size be recognized as "UB" > [contrary to the definition of UB, incidentally], which means that what > used to be the idiomatic way of doing a rotate left is explicitly invalid. > C compilers have since followed suit. I don't know if C compilers would > have started requiring that programmers replace the nice clean idiomatic > ways of doing bit-rotate operations with slower ways that many compilers > won't optimize, had it not been for the C++ requirements. > From §6.5.7 in C11 (N1570): If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined. From §5.8 in C++14 (N3797): The behavior is undefined if the right operand is negative, or greater than or equal to the length in bits of the promoted left operand It seems to me that C and C++ follow /exactly/ the same rules here. I haven't bothered checking other versions of the standards, so it is conceivable that the details have changed - I leave it to you to dig out chapter and verse if you still think there is any substance to your claims here.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
C++ forcing unnecessary changes to C? "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-18 20:34 +0800
Re: C++ forcing unnecessary changes to C? Thiago Adams <thiago.adams@gmail.com> - 2016-11-18 05:09 -0800
Re: C++ forcing unnecessary changes to C? "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-18 21:42 +0800
Re: C++ forcing unnecessary changes to C? jameskuyper@verizon.net - 2016-11-18 11:14 -0800
Re: C++ forcing unnecessary changes to C? jameskuyper@verizon.net - 2016-11-18 11:10 -0800
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-19 15:26 +0100
Re: C++ forcing unnecessary changes to C? "James R. Kuyper" <jameskuyper@verizon.net> - 2016-11-19 10:09 -0500
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-20 13:47 +0100
Re: C++ forcing unnecessary changes to C? Thiago Adams <thiago.adams@gmail.com> - 2016-11-21 03:25 -0800
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-21 14:15 +0100
Re: C++ forcing unnecessary changes to C? Thiago Adams <thiago.adams@gmail.com> - 2016-11-21 05:39 -0800
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-18 14:26 +0100
Re: C++ forcing unnecessary changes to C? "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-18 21:41 +0800
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-18 15:20 +0100
Re: conduct in comp.lang.c "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-18 22:23 +0800
Re: C++ forcing unnecessary changes to C? Philipp Klaus Krause <pkk@spth.de> - 2016-11-18 15:16 +0100
Re: C++ forcing unnecessary changes to C? "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-18 22:20 +0800
Re: C++ forcing unnecessary changes to C? jameskuyper@verizon.net - 2016-11-18 11:18 -0800
Re: C++ forcing unnecessary changes to C? supercat@casperkitty.com - 2016-11-18 07:15 -0800
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-18 16:55 +0100
Re: C++ forcing unnecessary changes to C? supercat@casperkitty.com - 2016-11-18 08:31 -0800
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-18 17:38 +0100
Re: C++ forcing unnecessary changes to C? John Bode <jfbode1029@gmail.com> - 2016-11-18 07:09 -0800
Re: C++ forcing unnecessary changes to C? Thiago Adams <thiago.adams@gmail.com> - 2016-11-18 07:22 -0800
Re: C++ forcing unnecessary changes to C? Thiago Adams <thiago.adams@gmail.com> - 2016-11-18 07:31 -0800
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-18 17:04 +0100
Re: C++ forcing unnecessary changes to C? jacobnavia <jacob@jacob.remcomp.fr> - 2016-11-18 16:37 +0100
Re: C++ forcing unnecessary changes to C? "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-18 23:53 +0800
Re: C++ forcing unnecessary changes to C? supercat@casperkitty.com - 2016-11-18 08:00 -0800
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-18 17:34 +0100
Re: C++ forcing unnecessary changes to C? Keith Thompson <kst-u@mib.org> - 2016-11-18 09:32 -0800
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-18 17:09 +0100
Re: C++ forcing unnecessary changes to C? jacobnavia <jacob@jacob.remcomp.fr> - 2016-11-18 18:02 +0100
Re: C++ forcing unnecessary changes to C? Robert Wessel <robertwessel2@yahoo.com> - 2016-11-21 03:26 -0600
Re: C++ forcing unnecessary changes to C? jacobnavia <jacob@jacob.remcomp.fr> - 2016-11-22 11:11 +0100
Re: C++ forcing unnecessary changes to C? jameskuyper@verizon.net - 2016-11-22 08:55 -0800
Re: C++ forcing unnecessary changes to C? Robert Wessel <robertwessel2@yahoo.com> - 2016-11-25 03:25 -0600
Re: C++ forcing unnecessary changes to C? supercat@casperkitty.com - 2016-11-25 10:00 -0800
Re: C++ forcing unnecessary changes to C? Keith Thompson <kst-u@mib.org> - 2016-11-25 12:30 -0800
Re: C++ forcing unnecessary changes to C? jacobnavia <jacob@jacob.remcomp.fr> - 2016-11-26 00:38 +0100
Re: C++ forcing unnecessary changes to C? supercat@casperkitty.com - 2016-11-26 10:44 -0800
Re: C++ forcing unnecessary changes to C? jacobnavia <jacob@jacob.remcomp.fr> - 2016-11-26 20:44 +0100
Re: C++ forcing unnecessary changes to C? supercat@casperkitty.com - 2016-11-26 12:38 -0800
Re: C++ forcing unnecessary changes to C? jacobnavia <jacob@jacob.remcomp.fr> - 2016-11-26 21:00 +0100
Re: C++ forcing unnecessary changes to C? jameskuyper@verizon.net - 2016-11-18 11:04 -0800
Re: [OT] discipline and obedience "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-19 22:53 +0800
Re: C & C++ Committee "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-19 22:55 +0800
Re: C & C++ Committee jameskuyper@verizon.net - 2016-11-19 08:02 -0800
Re: C & C++ Committee "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-20 00:09 +0800
Re: C & C++ Committee jameskuyper@verizon.net - 2016-11-19 08:35 -0800
Re: C & C++ Committee fir <profesor.fir@gmail.com> - 2016-11-19 08:51 -0800
Re: Do you write C programs? "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-20 01:00 +0800
Re: C & C++ Committee "Mr. Man-wai Chang" <toylet.toylet@gmail.com> - 2016-11-20 00:59 +0800
Re: C++ forcing unnecessary changes to C? jacobnavia <jacob@jacob.remcomp.fr> - 2016-11-22 11:14 +0100
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-22 12:05 +0100
Re: C++ forcing unnecessary changes to C? jacobnavia <jacob@jacob.remcomp.fr> - 2016-11-22 14:51 +0100
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-22 15:50 +0100
Re: C++ forcing unnecessary changes to C? BartC <bc@freeuk.com> - 2016-11-22 15:01 +0000
Re: C++ forcing unnecessary changes to C? Keith Thompson <kst-u@mib.org> - 2016-11-22 08:58 -0800
Re: C++ forcing unnecessary changes to C? jacobnavia <jacob@jacob.remcomp.fr> - 2016-11-22 18:08 +0100
Re: C++ forcing unnecessary changes to C? BartC <bc@freeuk.com> - 2016-11-22 18:14 +0000
Re: C++ forcing unnecessary changes to C? Ian Collins <ian-news@hotmail.com> - 2016-11-23 08:33 +1300
Re: C++ forcing unnecessary changes to C? BartC <bc@freeuk.com> - 2016-11-22 19:42 +0000
Re: C++ forcing unnecessary changes to C? Ian Collins <ian-news@hotmail.com> - 2016-11-23 08:51 +1300
Re: C++ forcing unnecessary changes to C? Keith Thompson <kst-u@mib.org> - 2016-11-22 12:13 -0800
Re: C++ forcing unnecessary changes to C? BartC <bc@freeuk.com> - 2016-11-22 21:35 +0000
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-23 00:47 +0100
Re: C++ forcing unnecessary changes to C? Keith Thompson <kst-u@mib.org> - 2016-11-22 12:09 -0800
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-23 00:40 +0100
Re: C++ forcing unnecessary changes to C? jacobnavia <jacob@jacob.remcomp.fr> - 2016-11-26 01:27 +0100
Re: C++ forcing unnecessary changes to C? David Brown <david.brown@hesbynett.no> - 2016-11-26 01:48 +0100
Re: C++ forcing unnecessary changes to C? Nathan Wagner <nw@hydaspes.if.org> - 2016-11-24 18:09 +0000
csiph-web