[RFC] Throwing an exception with null pointers
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Mon Apr 14 15:30:26 UTC 2025
On 14/04/2025 9:49 PM, a11e99z wrote:
> On Saturday, 12 April 2025 at 23:11:41 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> I've been looking once again at having an exception being thrown on
>> null pointer dereferencing.
>
> null pointer in x86 is any pointer less than 0x00010000
The null page right, and how exactly did you get access to a value that
isn't 0 or a valid pointer?
Program corruption. Which should only be possible in non- at safe code.
> also what about successful dereferencing 0x23a7b63c41704h827? its
> depends: reserved this memory by process, committed, mmaped etc
How did you get this value? Program corruption.
> failure for any "wrong" pointer should be same as for 0x0000....000
> (pure NULL)
Null (0) is a special value in D, these other values are simply assumed
to be valid. Of course its not possible to get these other values
without calling out of @safe code where program corruption can occur.
> imo need to dig into .net source and grab their option
.net is an application VM, and for all intents and purposes they will be
injecting read barriers before each null dereference.
They also have strong guarantees that you cannot have a invalid to a
pointer, pointer. It must be null or point to a valid object.
It isn't as simple as copying them.
Plus they have the type state analysis as part of the language to handle
nullability!
More information about the Digitalmars-d
mailing list