@safe - why does this compile?
ketmar
ketmar at ketmar.no-ip.org
Mon Jul 16 16:25:36 UTC 2018
Johan Engelen wrote:
> On Friday, 13 July 2018 at 14:51:17 UTC, ketmar wrote:
>>
>> yeah. in simple words: safe code is *predictable*, but not
>> "segfault-less". segfaults (null dereferences) in safe code are allowed,
>> 'cause they have completely predictable behavior (instant program
>> termination).
>>
>> @safe doesn't free you from doing your null checks, it protects you from
>> so-called "undefined behavior" (aka "unpredictable execution results").
>> so when we are talking about "memory safety", it doesn't mean that your
>> code cannot segfault, it means that your code won't corrupt random
>> memory due to misbehaving.
>
> This is not true when using LDC (and I'd expect the same for GDC).
> With LDC, dereferencing `null` is undefined behavior regardless of
> whether you are in an @safe context or not.
>
> - Johan
then those compilers are broken, and should be fixed.
More information about the Digitalmars-d-learn
mailing list