Value of a null pointer
Paul_L_Schauble at cup.portal.com
Paul_L_Schauble at cup.portal.com
Sat Apr 23 20:04:45 AEST 1988
I don't want to start the null pointer discussion all over again. But I have
a co-worker claiming that C requires that a null pointer be binary zero. He
cites two reasons:
1. An uninitialized external is set to zero bits. C defines an uninitialized
external pointer to be a null pointer. Therefore zero bits must be a null
pointer.
2. One can use calloc to allocate an array of pointers. The initial value of
this array must be null pointers. calloc sets the area to zero bits.
Therefore.......
Unfortunately, I don't have a copy of the proposed ANSI standard. My
recollection is that in both cases the pointer values are undefined.
Also, does the new standard require that a cast of a literal zero always
does the right thing? That is, are
ptr_type_var = (ptr_type)0; /* assigns null pointer */
ptr_type_var = 0; /* assigns null pointer */
func( (ptr_type)0 ); /* function expecting pointer type */
Are all of these always correct?
I believe that C does not require the null pointer to be zero and that there
are machines running it where the null pointer is non-zero. What I need, if
possible, are specific citations.
Thanks,
Paul
More information about the Comp.lang.c
mailing list