dereferencing null

Jonathan M Davis jmdavisProg at gmx.com
Mon Mar 5 20:27:17 PST 2012


On Tuesday, March 06, 2012 05:11:30 Martin Nowak wrote:
> There are two independent discussions being conflated here. One about
> getting more
> information out of crashes even in release mode and the other about
> adding runtime checks to prevent crashing merely in debug builds.

A segfault should _always_ terminate a program - as should dereferencing a 
null pointer. Those are fatal errors. If we had extra checks, they would have 
to result in NullPointerErrors, not NullPointerExceptions. It's horribly 
broken to try and recover from dereferencing a null pointer. So, the question 
then becomes whether adding the checks and getting an Error thrown is worth 
doing as opposed to simply detecting it and printing out a stack trace. And 
throwing an Error is arguably _worse_, because it means that you can't get a 
useful core dump.

Really, I think that checking for null when dereferencing is out of the 
question. What we need is to detect it and print out a stacktrace. That will 
maximize the debug information without costing performance.

- Jonathan M Davis


More information about the Digitalmars-d mailing list