the nil pointer is not zero

Stephen Clamage steve at taumet.com
Sat Nov 24 16:27:31 AEST 1990


bright at nazgul.UUCP (Walter Bright) writes:

>In article <14516 at smoke.brl.mil> gwyn at smoke.brl.mil (Doug Gwyn) writes:
>/I don't think so.  What good would it do you to know how a null pointer
>/is represented?  There is nothing useful you can do about that.

>1. Explanations of how C works become much simpler (note the endless debate
>   on usenet about NULL and 0).

I have to disagree with Walter here.  Consider Pascal as a counter-
example.  A pointer either points to a particular object, or it has
the value nil; 'nil' is a keyword.  A nil pointer points nowhere.  It
is always an error to dereference a nil pointer, always caught at run time
(in a standard-conforming Pascal system).  What could be simpler than that?

The confusion in C stems not from nil pointers which might not be
zero, but from using a literal zero to represent nil pointers.  This
leads to the 'obvious' conclusion that a nil pointer must point at
address zero and be represented by all-bits-zero.  The obvious
conclusion is unfortunately not always correct.
-- 

Steve Clamage, TauMetric Corp, steve at taumet.com



More information about the Comp.lang.c mailing list