@safe question

Paul Backus snarwin at gmail.com
Mon Jan 10 03:21:46 UTC 2022


On Monday, 10 January 2022 at 01:16:31 UTC, forkit wrote:
> On Sunday, 9 January 2022 at 21:56:05 UTC, Salih Dincer wrote:
>>
>> Try the @trusted and in/out:
>> ...
>> ..
>> .
>
> thanks for introducing me to the in/out feature of D :-)
>
> I'll certainly look into that feature more.
>
> But my question still remains:
>
> //pointers ~= &str; // why is this *not* allowed in @safe
> pointers ~= &strings[i]; // while this *is* allowed in @safe

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.


More information about the Digitalmars-d-learn mailing list