>>> I recollect a vague discussion years ago that on one particular
machine, NULL wasn't 0 or some variant of 0.  Obviously, that machine
survived time so well, I can't even recall what it was.  And there was
at least a few machines that had special hardware exception handlers it
you tried to write to 0.

Writing/reading via NULL is definitely suspect ... and, as you say, CPU 
hardware can detect that.

However simply using NULL as a pointer value is NOT a problem ... just don't 
access via it!

Some modified compilers and run-time libraries [Salford C?] CAN use a "magic 
number" for unassigned variables, bad pointers, NULL
pointers etc in order to trap illegal use - but everthing can work out OK in 
the end ... as long as NULL is not used in arithmetic
expressions or other nasties.

Richard

----- Original Message ----- 
From: "J.C. Wren" <jcw...@jcwren.com>
To: <mspgcc-users@lists.sourceforge.net>
Sent: Saturday, March 27, 2004 1:16 PM
Subject: Re: [Mspgcc-users] Why #define NULL 0?


> Indrek Rebane wrote:
>
> > Hey folks,
> >
> > Russell Nelson wrote:
> >
> >> Even if there was a good reason to change it, there's way too
> >> much code that does this kind of thing:
> >>
> >> foo = malloc(10); if (!foo) exit(1);
> >
> >
> > Which is a really bad programming practice. After all, ain't unary
> > logical operations with pointers illegal? Better way would be:
> >
> > if (foo == NULL)
> >
> > Which gives nice int value to if for evaluation in C (bool in C++).
> >
> > Indrek
> >
>     Let's put it this way:  Having used 'C' compilers on at least 11
> different architectures (MSP430, AVR, x86, AM29000, 8051, 68xx, 68xxxx,
> VAX, Z80, 80196, SH/3) by at least as many compiler vendors, it's never
> been a problem.  And GCC, which has pretty darn good rule checking with
> -W -Wall doesn't complain.  Can't say I remember what lint in strict
> mode might recommend.
>
>     Two of the more common constructs in C are: "if (!index ("this",
> "is") ..." and "if (!(ptr = malloc (12)))..."  If it's illegal, well
> over 50% of the software ever written is wrong.
>
>     I recollect a vague discussion years ago that on one particular
> machine, NULL wasn't 0 or some variant of 0.  Obviously, that machine
> survived time so well, I can't even recall what it was.  And there was
> at least a few machines that had special hardware exception handlers it
> you tried to write to 0.
>
>     So it's pretty much a moot point.  In Idealland (about 20km north of
> Utopia), everyone might compare to NULL.  But it ain't gonna happen.
>
>     --jc
>
>
> -------------------------------------------------------
> This SF.Net email is sponsored by: IBM Linux Tutorials
> Free Linux tutorial presented by Daniel Robbins, President and CEO of
> GenToo technologies. Learn everything from fundamentals to system
> administration.http://ads.osdn.com/?ad_id=1470&alloc_id=3638&op=click
> _______________________________________________
> Mspgcc-users mailing list
> Mspgcc-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mspgcc-users


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.631 / Virus Database: 404 - Release Date: 17/03/04


Reply via email to