NULL again

Chip Salzenberg chip at ateng.ateng.com
Sat Oct 8 03:03:28 AEST 1988


William Davidsen is upset because I posted a correction to an article of
his.  He claims that my quotation of his article was taken out of context;
perhaps this is true.  If so, I apologize.

Now let's get the facts straight.

The original poster, long since forgotten, correctly wrote:
>The computer's internal representation of a null pointer may not
>be the same as the internal representation of the integer 0.

Then William Davidsen wrote:
>  Just not true in the real world. There are hundreds of programs
>written by "all the world's a VAX" types who use NULL as a pointer
>(uncast) in procedure calls.

To which I replied:
>That's true but irrelevant.  THOSE PROGRAMS ARE NOT PORTABLE.  After all,
>bitwise representation is not the only issue.  Sometimes pointers are
>_larger_ than ints!

Mr. Davidsen, considering my response a flame, flames back:
>  Do you see a statement that says they are portable? Do you??!!
[...]
>  I was pointing out that NULL is not portably 0 because (a) there are
>lots of implementation which don't do it that way (real world) and (b)
>dbANS says it will evaluate to a "pointer constant." I quoted section,
>page, and line number showing this, making only the point that NULL
>isn't zero.

Unfortunately, Mr. Davidsen is no more correct when angry than when calm.
Both K&R and the dpANS permit:

	#define NULL 0

(Of course, dpANS also permits "((void *) 0)" in place of "0".)

The original poster made the point that when a compiler sees

	char *p = NULL;

it may or may not move a bit pattern of all zeros into the variable "p".
Regardless, the definition of NULL as an unadorned zero is quite correct.
That is the reason why all NULL pointer parameters must be cast (in the
absence of prototypes, of course).

Perhaps Mr. Davidsen is aware of these facts.  However, I felt that his
posting was misleading, so I posted a correction.  I am sorry that my
correction has caused a disturbance.
-- 
Chip Salzenberg             <chip at ateng.com> or <uunet!ateng!chip>
A T Engineering             Me?  Speak for my company?  Surely you jest!
	   Beware of programmers carrying screwdrivers.



More information about the Comp.lang.c mailing list