How does D handle null pointers?

Steven Schveighoffer schveiguy at yahoo.com
Mon Aug 23 05:32:39 PDT 2010


On Fri, 20 Aug 2010 22:07:03 -0400, Adam B <cruxic at gmail.com> wrote:

>> Walter has refused to put in null checks on the theory that the OS does  
>> it for
>> you - hence the segfault. Of course, then the only way to get a  
>> stacktrace is to
>> either have a segfault handler which prints one or to look at a core  
>> dump
>> (assuming that you get one). Neither is a very pleasant solution.
>
> I see.  I guess I can sympathize with Walter's perspective somewhat -
> it does feel redundant for both the application AND the OS to be
> checking pointers.  Perhaps then it is the OS that's holding us back.
> If only we could trap a segfault signal and have the OS tell us which
> thread caused it and provide some mechanism to resume the thread with
> an exception...  Hopefully some Linux kernel developers are reading
> this ;)

Once you get a seg fault, your code is not guaranteed to be correct.   
Memory that contained code or data could have been corrupted.  Even your  
stack may be corrupt.

I think D should handle it by making a best effort to print out a trace  
and exit.

-Steve


More information about the Digitalmars-d mailing list