Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.lisp > #33127
| From | Barry Fishman <barry@ecubist.org> |
|---|---|
| Newsgroups | comp.lang.lisp |
| Subject | Re: TIL: C++17 sequences assignment the wrong way. |
| References | <20190718203039.263@kylheku.com> <7nzhlaglhf.fsf@ecube.ecubist.org> <20190719093907.216@kylheku.com> |
| Message-ID | <7ntvbhg5pg.fsf@ecube.ecubist.org> (permalink) |
| Organization | Easynews - www.easynews.com |
| Date | 2019-07-19 15:55 -0400 |
On 2019-07-19 16:45:11 +00, Kaz Kylheku wrote:
> On 2019-07-19, Barry Fishman <barry@ecubist.org> wrote:
>>
>> On 2019-07-19 03:36:55 +00, Kaz Kylheku wrote:
>>> C++17 adds a sequence point to assignment. E1 = E2 requires E2 to be
>>> completely evaluated first, then E1.
>>>
>>> Wow, what a jaw-droppingly moronic moment in computing history.
>>>
>>> They had the right motivation to fix a flaw, at least in one small area,
>>> and establish an order where there is chaos.
>>>
>>> Then they drop the ball by making it backwards.
>>
>> int *p = an_array_of_ints;
>> for (int i = 0; i < 3; i++) {
>> *p++ = *p + 1;
>> }
>
> In C++17, this will reliably calculate the prior value of *p + 1,
> store it in *p, and increment p.
>
> But under left-to-right, that can be done just fine:
>
> *p = *p++ + 1;
Yes. But to my Infix language sense, this is less clear, especially
where the right hand side is more complex.
Also, I think infix assignment (ignoring side effects) usually makes more sense
in a right to left evaluation order.
In gcc and g++, although I am not sure if legal generally in C++17:
b = a = 3;
as opposed to Lisp, where one would do:
(setq a 3 b a)
Or explicit ordered:
(setq b (setq a 3))
Personally I just try to avoid side effects (and C/C++).
--
Barry Fishman
Back to comp.lang.lisp | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
TIL: C++17 sequences assignment the wrong way. Kaz Kylheku <847-115-0292@kylheku.com> - 2019-07-19 03:36 +0000
Re: TIL: C++17 sequences assignment the wrong way. Barry Fishman <barry@ecubist.org> - 2019-07-19 10:14 -0400
Re: TIL: C++17 sequences assignment the wrong way. Kaz Kylheku <847-115-0292@kylheku.com> - 2019-07-19 16:45 +0000
Re: TIL: C++17 sequences assignment the wrong way. Barry Fishman <barry@ecubist.org> - 2019-07-19 15:55 -0400
Re: TIL: C++17 sequences assignment the wrong way. Stefan Monnier <monnier@iro.umontreal.ca> - 2019-07-19 13:30 -0400
Re: TIL: C++17 sequences assignment the wrong way. Kaz Kylheku <847-115-0292@kylheku.com> - 2019-07-19 18:44 +0000
csiph-web