safety: null checks
anonymous at example.com
Mon Nov 23 01:26:15 UTC 2020
On Monday, 23 November 2020 at 00:50:03 UTC, Ola Fosheim Grostad
> Well, the spec said that the value should be valid, which null
> by definition should not have, then the example comment
> mentioned a well defined crash which is a contradiction in
> So the spec is unsound.
I wrote that part of the spec. My intent was to define null as a
safe value. For other pointer-like types I wrote: "A [thing] is
safe when it is `null` or [whatever]". Please feel free to add
that phrase for pointers, too, or adjust the text in any other
way that makes it more clear that null is a safe value.
> What you would require from a high level language is that
> dereferencing null pointers is caught either at compile time or
> at runtime. But that is slow on some platforms. So this is just
> an example of the implementation being the spec, and actual
> document does not make sense in a general setting.
The reference implementation treats null as a safe value. Yes,
that can imply additional checks at run time. That's what Walter
chose, for better or worse.
More information about the Digitalmars-d