safety: null checks
Ola Fosheim Grøstad
ola.fosheim.grostad at gmail.com
Mon Nov 23 12:39:05 UTC 2020
On Monday, 23 November 2020 at 12:28:39 UTC, Patrick Schluter
wrote:
> No. null is not a trap representation as a C standard would
> call it. It is a valid value for a pointer. Dereferencing it is
> an entirely other thing.
A trap is an interrupt at the hardware level. It has nothing to
do with C.
>> Trivially invalid.
>
> Nope.
Yes. "nothing" in not a valid value for "int". That is trivially
invalid.
Try to think of null as an empty set.
> Nope. In the case of D. The error generated by dereferencing a
> null pointer is a defined behaviour. As defined as is calling
> abort() in a C program.
You are speaking of DMD, not the spec?
> The issue with null pointer dereferencing has nothing to do
> with its definition but with its implementation as the defined
> behaviour of aborting the program is not guaranteed in all
> circumstances (null pointer + offset big enough to hit a real
> page).
My argument is based on the spec and what is required to get to
something that is consistent/sound and portable.
Also, as it has been pointed out, it does not work this way in
shipping compilers so the spec should provide implemtation notes
on what actually happens in shipping compilers.
More information about the Digitalmars-d
mailing list