float init 0 request
Mindy Batek (0xEAB)
desisma at heidel.beer
Sat Aug 22 13:14:54 UTC 2026
On Saturday, 22 August 2026 at 09:37:46 UTC, Nick Treleaven wrote:
> On Friday, 21 August 2026 at 20:54:25 UTC, Mindy Batek (0xEAB)
> wrote:
>> ```d
>> int foo() const
>> {
>> for (auto next = (() @trusted => cast() this.next)(); next
>> !is null; next = next.next)
>> {
>
> Surely that is incorrect to use `cast()`, because fields of
> `next` could be mutated.
Indeed, a cleaned up version would be even more verbose, maybe
something like…
```d
int foo() const
{
() @trusted {
for (auto next = this.next; next !is null; next = next.next)
{
const next2 = next;
next = null;
() @safe {
// […]
}();
}();
```
Anyway, it was more like a short example of a workaround — with
no special regard given to correctness.
> Can't you just declare the node type instead:
> ```d
> const(Node)* next = this.next;
> ```
The node type is an `abstract class` in my case, i.e. a pointer
already.
I think we can agree that an elegant language shouldn’t require
me to create a pointer to a pointer just the work around the type
system.
Needless to say, that extra pointer would likely need an extra
memory allocation as well.
More information about the Digitalmars-d
mailing list