@system blocks and safer @trusted (ST) functions

Paul Backus snarwin at gmail.com
Mon Jul 26 13:48:07 UTC 2021


On Monday, 26 July 2021 at 09:08:05 UTC, Dominikus Dittes Scherkl 
wrote:
> On Sunday, 25 July 2021 at 17:47:40 UTC, Paul Backus wrote:
>
>> ```d
>> @system {
>>    return array.ptr[favoriteNumber()];
>> }
>> ```
>>
>> I make the following claims:
>>
>> 1. This code is memory-safe.
>
> No, it's not. You use something that is not a literal, so it 
> may change.

I agree that *future versions* of the code may not be memory-safe 
if `favoriteNumber` is changed, but that does not mean the 
*current version* is unsafe.

If you believe that the current version is unsafe, you should be 
able to demonstrate this unsafety by writing a `@safe` program 
that uses the current version to cause undefined behavior.


More information about the Digitalmars-d mailing list