I know that in C++ the use of NULL is almost deprecated.
Stroustrup suggests to prefer 0, because no object is allocated at the
address 0.
He's wrong (if he actually suggests it for that reason). The constant
zero assigned or compared to a pointer is evaluated as a null pointer,
whatever value that has in that implementation (it might actually be all
bits set, or a 'trap' value). An implementation can put objects at an
address of zero if it likes.
Moreover, I don't think that exists a standard behaviour about Null
pointer deferencing.
It's explicitly undefined behaviour, and can cause demons to fly out of
your nose, or World War III, or an asteroid to hit your home town. It
may cause a trap (bus error, interrupt, signal, code dump or whatever)
but it may not (and will not on one of the most common CPU architectures
as well as on some systems under another common architecture).
(As for what happens when one dereferences a derived pointer, like a
structure member, that's even less defined if that's possible, because
many systems won't even trap it...)
It's something that happens at run time and a C++ compiler has no
control on it (IMHO).
Well, a compiler could issue code protecting every memory access...
Why on the Earth a person should try to dereference (with awareness) a
NULL pointer ???
Perhap the OP likes demons flying out of zir nose? I haven't tried it
myself, it might be a turn-on for some people (like banging heads
against a brick wall).
Chris C