Subject: Re: CVS commit: src/sys/ufs/lfs
To: Manuel Bouyer <bouyer@antioche.eu.org>
From: David Laight <david@l8s.co.uk>
List: source-changes
Date: 03/19/2006 20:20:18
On Sun, Mar 19, 2006 at 02:29:26PM +0100, Manuel Bouyer wrote:
> 
> Then maybe NULL should be defined to something else than 0 on those
> platforms ? I wonder how much things will break if we have NULL != 0
> though ...

Lots of stuff, but not for the reasons anyone has quoted...

IIRC, C allows any bit pattern to be used for the 'NULL' pointer.
However regardless of the actual value the following are all equivalent:

if (ptr), if (ptr != 0), if (ptr != 1 - 1), if (ptr = (void *)0)

NULL itself can be 0, or any compile time integer expression that evaluates
to zero, cast to (void *).

I also believe the compiler is required to initialise static pointers
(including those in structures) to the NULL value.

The code that breaks is anything that expects memset(ptr, 0, sizeof *ptr)
to initialise pointers in the structure to NULL.

The only platform I know that used -1 for its 'NULL' pointer in its usual
languages, had a C implementation that used 0.  Writing a compiler to do
anything else, and expecting any standard programs to run, was too hard.

	David

-- 
David Laight: david@l8s.co.uk