null dereference

Jonathan M Davis jmdavisProg at gmx.com
Sat Mar 15 16:22:49 PDT 2014


On Saturday, March 15, 2014 11:05:42 luka8088 wrote:
> I was thinking and I am not sure about the reason for not having some
> king of safeguard for null dereferencing in version(assert)/debug builds.
> 
> One possible reason that comes to mind is that it somewhat affects
> performance but should this really be an issue in version(assert)/debug
> build? Especially given the benefit of having file/line number and stack
> information outputted.

Essentially what it comes down to is the fact that because the OS already 
detects null pointer dereferences for you (hence the segfault or access 
violation that you get when it occurs), Walter considers it unnecessary. If 
you want more details, look at the resulting core dump in a debugger or run 
the program in a debugger to begin with. Now, that obviously doesn't always 
work, which is part of why many folks argue in favor of adding additional 
checks, but that's Walter's position.

I believe that there was some work done to make it so that druntime would 
detect a segfault and print a stacktrace when that happens, but it's not 
enabled normally, and I don't know quite what state it's in. That would 
probably be the ideal solution though, since it gives you the stacktrace 
without requiring additional checks.

- Jonathan M Davis


More information about the Digitalmars-d mailing list