What is the really pointing to?

John S. Price john at stat.tamu.edu
Tue May 8 19:58:14 AEST 1990


In article <21910 at dartvax.Dartmouth.EDU> pete at othello.dartmouth.edu (Pete Schmitt) writes:
>What is the null pointer really pointing to?
>[declaration deleted]
>struct entry n1, n2, n3, *list_pointer = &n1;
>
>n1.next = &n2;
>n2.next = &n3;
>n3.next = (struct entry *) 0;   /* <-- what is this pointing to, address 0? */

Oh no.. Here we go again.
The (struct entry *) 0 is not address 0.  The NULL pointer is not pointing
to ANYTHING.  Nothing.  Zip.  Zilcho.  It is exactly what it is called.
Nobody really cares what the pointer actually contains, although it
is usually a bit pattern of zero (Yes, I know it's not always.  Segmented
arch. can cause this to be weird)  It doesn't have to be a bit pattern of
zero, though.  But, nobody cares what it is.  THAT pattern, whatever it is,
is the NULL pointer.

C uses 0 to represent for a null pointer for lack of anything better.  0 is 
overloaded to mean two things, depending on it's context.  If it is in an 
integer context, it means the number zero.  If it is used in a pointer context,
as in the above context, then it means a null pointer, whatever that value 
might be.  0 is a SPECIAL CASE to the compiler.

A null pointer doesn't pointer anywhere.  That's its purpose.  To point 
nowhere.  

This was just recently discussed, but I guess that you missed that discussion.


--------------------------------------------------------------------------
John Price                   |   It infuriates me to be wrong
john at stat.tamu.edu           |   when I know I'm right....
--------------------------------------------------------------------------



More information about the Comp.lang.c mailing list