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

From: James Dow Allen (
Date: 12/01/03

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

"xarax" <> wrote in message news:<kGnyb.20275$>...
> "Kelsey Bjarnason" <> 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)
               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.