safety: null checks

Paul Backus snarwin at gmail.com
Sun Nov 22 22:36:40 UTC 2020


On Sunday, 22 November 2020 at 22:16:11 UTC, Dibyendu Majumdar 
wrote:
> On Sunday, 22 November 2020 at 15:25:48 UTC, Q. Schroll wrote:
>> On Sunday, 22 November 2020 at 11:52:13 UTC, Dibyendu Majumdar 
>> wrote:
>>> Above fails because b is null. But why doesn't the compiler 
>>> say so? It seems like a very basic safety check.
>>
>> Nullpointer exceptions aren't a safety issue since the program 
>> crashes. For it to be a safety issue, it would need to have 
>> "bad consequences" e.g. writes to memory at locations the 
>> program isn't supposed to.
>
> Right. A crash isn't a bad consequence, of course.

Memory safety is concerned specifically with avoiding undefined 
behavior. Crashing the program isn't undefined behavior, so it's 
allowed in @safe code.


More information about the Digitalmars-d mailing list