On Monday, 10 January 2022 at 03:21:46 UTC, Paul Backus wrote:
Taking the address of a local variable is forbidden in @safe
code. Even though str is a ref variable that points to a
heap-allocated string, it is still considered a local variable
because it is declared inside the body of a function.
but strings[] is also a local variable declared in the body of
the same function, and yet within the foreach statement, @safe
lets me do:
pointers ~= &strings[i]; // safe
...but not this below, where str is just a reference to the exact
same memory as the statement above... is it not? How is this
below any more or less safe than the above statement.
pointers ~= &str; // not safe - ok, but why??