void main()
{
auto a = 0;
auto b = 0;
auto c = 1;
auto ptr = &(c ? a : b);
*ptr = 8;
assert(a == 8);
ptr = &(c ? b : a);
*ptr = 2;
assert(a + b == 10);
}
It's just beautiful
Thread overview | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
October 07 One of the thing I like in D | ||||
---|---|---|---|---|
| ||||
It's just beautiful |
October 08 Re: One of the thing I like in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Boaz Ampleman | On Monday, 7 October 2024 at 20:03:46 UTC, Boaz Ampleman wrote: >
It's just beautiful But why pointers?
|
October 08 Re: One of the thing I like in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dom Disc | On Tuesday, 8 October 2024 at 08:38:15 UTC, Dom Disc wrote: >On Monday, 7 October 2024 at 20:03:46 UTC, Boaz Ampleman wrote: >
It's just beautiful But why pointers? [...] yeah sorry, that missed a bit of comments. Here there are: the point was that the conditional expression yields a lvalue, hence it's candidate to be a sub-expression of the address expression. That is just something I had never seen before. I just wanted to share the joy ;) |
October 08 Re: One of the thing I like in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Dom Disc | On Tuesday, 8 October 2024 at 08:38:15 UTC, Dom Disc wrote: >On Monday, 7 October 2024 at 20:03:46 UTC, Boaz Ampleman wrote: >
It's just beautiful But why pointers?
That's kinda flexible actually |
October 09 Re: One of the thing I like in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Boaz Ampleman | Yup. It's designed to look good! |
October 11 Re: One of the thing I like in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Boaz Ampleman | On Monday, 7 October 2024 at 20:03:46 UTC, Boaz Ampleman wrote: >
It's just beautiful With next dmd you can use use ref variables aswell as
But for some reason the last statement doesn't behave as I believe it should. Is this behavior expected? For reference see https://dlang.org/changelog/pending.html#dmd.reflocal. |
October 12 Re: One of the thing I like in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Per Nordlöw | On Friday, 11 October 2024 at 23:04:20 UTC, Per Nordlöw wrote: >With next dmd you can use use ref variables aswell as
But for some reason the last statement doesn't behave as I believe it should. Is this behavior expected? For reference see https://dlang.org/changelog/pending.html#dmd.reflocal. This has to be a bug ;) |
October 12 Re: One of the thing I like in D | ||||
---|---|---|---|---|
| ||||
Posted in reply to Per Nordlöw | On Friday, 11 October 2024 at 23:04:20 UTC, Per Nordlöw wrote: >On Monday, 7 October 2024 at 20:03:46 UTC, Boaz Ampleman wrote: >[...] It's just beautiful With next dmd you can use use ref variables aswell as
But for some reason the last statement doesn't behave as I believe it should. Is this behavior expected? For reference see https://dlang.org/changelog/pending.html#dmd.reflocal.
If you re-write the example in terms of pointers, it is equivalent to:
|