safety: null checks

Dibyendu Majumdar mobile at
Mon Nov 23 00:26:26 UTC 2020

On Monday, 23 November 2020 at 00:17:12 UTC, Paul Backus wrote:

> The relevant part of the spec is the one on "safe values" [1]:
>> A pointer is safe when:
>>    1. it can be dereferenced validly [i.e. with defined 
>> behavior], and
>>    2. the value of the pointee is safe.
> If null is a safe value, then dereferencing it must be defined 
> behavior. If null is an unsafe value, then it must not be 
> allowed to appear in @safe code. Either way, a compiler that 
> allows null in @safe code but treats a null dereference as 
> undefined behavior is buggy.
> [1]

Hmm, null values are not the same as dereferncing null values.
A null in itself is okay, but dereferencing null cannot be.

More information about the Digitalmars-d mailing list