Re: Faulting on dereferencing NULL (was Re: Style Question - Checking for Poor Parameters)

From: James Dow Allen (jdallen2000_at_yahoo.com)
Date: 12/01/03


Date: 30 Nov 2003 20:50:13 -0800


"xarax" <xarax@email.com> wrote in message news:<kGnyb.20275$n56.12549@newsread1.news.pas.earthlink.net>...
> "Kelsey Bjarnason" <kelseyb@lightspeed.bc.ca> wrote in message
> news:pan.2003.11.30.01.24.43.403168@lightspeed.bc.ca...
> > 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)
               return FAILURE;
could be "optimized" to just
         if (*p == 0)
               return FAILURE;

(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
historical trivia.

James