Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!mnetor!uunet!seismo!gatech!bloom-beacon!think!ames!oliveb!sun!gorodish!guy
From: guy%gorodish@Sun.COM (Guy Harris)
Newsgroups: comp.lang.c
Subject: Re: NULL, zero, and readable code
Message-ID: <23204@sun.uucp>
Date: Fri, 10-Jul-87 16:00:43 EDT
Article-I.D.: sun.23204
Posted: Fri Jul 10 16:00:43 1987
Date-Received: Sun, 12-Jul-87 13:58:23 EDT
References: <8170@brl-adm.ARPA> <44200004@uicsrd>
Sender: news@sun.uucp
Lines: 57

> But I feel obligated to encourage the use of NULL over 0.
> Irregardless of style questions (or "theoretial" discussions), I
> have worked on systems where NULL was != 0, because 0 was a
> valid address.  It's incredibly annoying to have to search for all
> occurrences of 0 that are intended as a NULL pointer value.

Any C implementation that doesn't convert the constant 0 to a pointer
of the appropriate type, in the appropriate contexts, is buggy,
broken, wrong, invalid, etc., etc., etc..  ANY IMPLEMENTATION WHERE
THE STATEMENTS

	if (p == NULL)
		(do something)

and

	if (p == 0)
		(do something)

where "p" is of type "char *" don't generate equivalent code (if the
two "(do something)"s are the same) is broken.  The same is true of

	p = 0;

and

	p = NULL;

and of

	foo((char *)0);

and

	foo((char *)NULL);

It doesn't matter *what* bit pattern is used to represent a NULL
pointer; NO C IMPLEMENTATION THAT REQUIRES NULL TO BE DEFINED TO BE
THAT BIT PATTERN IS VALID.  Period.  End of discussion.

If 0 is a valid address, and objects have 0 as their address (there
are implementations where 0 is a valid address in the sense that you
won't get a fault by referencing it, but where no objects are placed
at that location, and many of these represent a null pointer by an
all-zeroes bit pattern), then the compiler MUST recognize 0 in the
appropriate context (one where it is to be converted to a null
pointer of the apprpriate type) and represent it as the bit pattern
used for null pointers in that implementation.

This may be counterintuitive, but that's just too bad; that's the way
C works, changing this would break too many programs written strictly
according to the rules, and it's not going to change.  (Besides, the
same thing happens when mixing the integral constant 0 and floating
point numbers, if 0.0 isn't represented by an all-zero bit pattern.)
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy@sun.com