D - Unsafe and doomed

Peter Alexander peter.alexander.au at gmail.com
Sun Jan 5 08:11:14 PST 2014


On Saturday, 4 January 2014 at 23:04:12 UTC, deadalnix wrote:
>> The list is endless. Why is null special?
>
> Because it is an instant crash, because it is not possible to 
> make it safe without runtime check, because it is known to fool 
> optimizer and cause really nasty bugs (typically, a pointer is 
> dereferenced, so the optimizer assume it isn't null and remove 
> null check after the dereference, and then the dereference is 
> removed as it is dead. a bugguy code that could have crashed 
> will know behave in random ways).

An instant crash is a very nice way to fail, compared to, for 
example, what failure means for an SQL injection or a buffer 
overrun. A crash is bad, but it's better than a program 
continuing to execute erroneously.

I have to agree with Walter here. Non-null is certainly nice, but 
it's just one kind of error out of a million, and not a 
particularly serious one at that.


More information about the Digitalmars-d mailing list