Re: Faulting on dereferencing NULL (was Re: Style Question - Checking for Poor Parameters)
From: James Dow Allen (jdallen2000_at_yahoo.com)
Date: 30 Nov 2003 20:50:13 -0800
"xarax" <firstname.lastname@example.org> wrote in message news:<kGnyb.email@example.com>...
> "Kelsey Bjarnason" <firstname.lastname@example.org> wrote in message
> > On Wed, 26 Nov 2003 04:12:34 -0500, Michael B Allen wrote:
> > > Not necessarily. Dereferecing NULL is going to fault on the spot.
> It depends on the target platform and how the compiler implements
FWIW, Unix on some (DEC?) machines, IIRC, stored 0 at location 0.
Thus, the code
if (p == NULL || *p == 0)
could be "optimized" to just
if (*p == 0)
(In a vaguely similar vein, Data General machines had special addresses
where *p automatically became (*p)++ or (*p)--, and special pointers
where *p automatically became **p.)
Don't blame any of this on me, please; I'm just reporting