Safety is not what you think
Basile B.
b2.temp at gmx.com
Mon Feb 5 14:26:45 UTC 2024
On Tuesday, 30 January 2024 at 15:38:26 UTC, Paul Backus wrote:
> [...]
> This definitely isn't allowed in C or C++. I wonder what the
> rationale is for having this behavior in D?
>
> [1]: https://dlang.org/spec/expression.html
An hypothesis is that this makes codegening the pre and the post
variants almost identical. The only difference is what is yield.
[Proof](https://gitlab.com/styx-lang/styx/-/blob/master/src/styx/backend/irgen.sx?ref_type=heads#L3383).
Now there's not much to say about the topic, I just thought it
was amusing to share that (user1234 is my noname nickname here)
as people might not realize how much certain expressions allows.
In the same vein you have the possibility to select an lvalue
with a conditional expression. Pretty sure nobody knows that the
following is legal
```d
int a,b;
int c = rand();
((c & 3) ? a : b) = 42;
```
More information about the Digitalmars-d-learn
mailing list