Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #169208
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: lvalue assignment difference between C and C++ |
| Date | 2023-02-06 21:19 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <87ilgemqyu.fsf@bsb.me.uk> (permalink) |
| References | <trltmg$21cft$1@dont-email.me> <0mvDL.68810$b7Kc.34465@fx39.iad> <trm2tb$224hr$1@dont-email.me> <trq970$2vkp9$1@dont-email.me> <44c37621-b302-472d-a48f-a6c6239ce5b7n@googlegroups.com> |
bart c <bart4858@gmail.com> writes: > On Monday, 6 February 2023 at 07:11:43 UTC, Paavo Helde wrote: > >> This would basically introduce a limited notion of 'reference' in the C >> language, which would make the language more complex to teach and learn. >> That's the opposite to the goals C currently has. >> >> And yes, having a simpler language in general means the programs written >> in it need to be more complex. Here it just means a couple of extra >> asterisks and ampersands, so not a big deal. > > C already has to deal differently with constructs like this to allow > them to be lvalues: > > A = x; > *A = x; > A[i] = x; > A.m = x > > Allowing: > > c ? A : B = x; Just to add an often overlooked detail... In C, what you wrote does parse as you intended: (c ? A : B) = x so you'll be told that = needs an lvalue on the left, but in C++ it parses as c ? A : (B = x) so you need to use ()s assign to the result of a conditional expression in C++. > is not much different, and little extra cognitive loads. In this last > example, A and B can be any of the forms in the first four examples, > plus nested ?: terms. > > The only thing that is somewhat different, is that the two lvalue > expressions (or more with nested ?:) need to have a more closely > compatible type than when they are r-values. However, if a compiler > simply transforms this into: > > *(c ? &A : &B) = x; > > then this is taken care of as normal. C could choose to define c ? A : B = x to mean *(c ? &A : &B) = x but there would be odd corner cases such as A or B being bit fields or declared with storage class 'register'. -- Ben.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-04 15:30 +0000
Re: lvalue assignment difference between C and C++ Richard Damon <Richard@Damon-Family.org> - 2023-02-04 11:04 -0500
Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-04 16:59 +0000
Re: lvalue assignment difference between C and C++ Richard Damon <Richard@Damon-Family.org> - 2023-02-04 13:02 -0500
Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-04 12:45 -0800
Re: lvalue assignment difference between C and C++ David Brown <david.brown@hesbynett.no> - 2023-02-05 11:42 +0100
Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-06 09:26 +0000
Re: lvalue assignment difference between C and C++ David Brown <david.brown@hesbynett.no> - 2023-02-06 14:13 +0100
Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-06 15:50 +0000
Re: lvalue assignment difference between C and C++ David Brown <david.brown@hesbynett.no> - 2023-02-06 20:08 +0100
Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 12:47 -0800
Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 13:03 -0800
Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-07 09:24 +0000
Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-07 11:08 -0800
Re: lvalue assignment difference between C and C++ Muttley@dastardlyhq.com - 2023-02-08 09:23 +0000
Re: lvalue assignment difference between C and C++ Blue-Maned_Hawk <bluemanedhawk@gmail.com> - 2023-02-08 22:13 -0500
Re: lvalue assignment difference between C and C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2023-02-08 22:53 -0500
Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-08 22:12 -0800
Re: lvalue assignment difference between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-08 02:52 +0000
Re: lvalue assignment difference between C and C++ Paavo Helde <eesnimi@osa.pri.ee> - 2023-02-06 09:11 +0200
Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 01:01 -0800
Re: lvalue assignment difference between C and C++ Richard Damon <Richard@Damon-Family.org> - 2023-02-06 07:42 -0500
Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 12:59 -0800
Re: lvalue assignment difference between C and C++ bart c <bart4858@gmail.com> - 2023-02-06 08:11 -0800
Re: lvalue assignment difference between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-06 21:19 +0000
Re: lvalue assignment difference between C and C++ Bonita Montero <Bonita.Montero@gmail.com> - 2023-02-07 07:44 +0100
Re: lvalue assignment difference between C and C++ Paavo Helde <eesnimi@osa.pri.ee> - 2023-02-07 09:18 +0200
Re: lvalue assignment difference between C and C++ Kaz Kylheku <864-117-4973@kylheku.com> - 2023-02-06 22:21 +0000
Re: lvalue assignment difference between C and C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-02-06 14:43 -0800
Re: lvalue assignment difference between C and C++ Paul N <gw7rib@aol.com> - 2023-02-07 03:17 -0800
Re: lvalue assignment difference between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-07 16:25 +0000
Re: lvalue assignment difference between C and C++ Paul N <gw7rib@aol.com> - 2023-02-08 13:19 -0800
Re: lvalue assignment difference between C and C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-02-08 23:46 +0000
Re: lvalue assignment difference between C and C++ Bonita Montero <Bonita.Montero@gmail.com> - 2023-02-04 19:41 +0100
Re: lvalue assignment difference between C and C++ Andrey Tarasevich <andreytarasevich@hotmail.com> - 2023-02-10 16:19 -0800
csiph-web