Benjamin Scott <benjamin_cail_sc...@...> wrote:
>
> According to my understanding, If a Pointer has the
> value of 0,
Pointers do not have integer values. Assigning a zero
valued constant to a pointer does not mean it has the
value zero. Instead, it means it is assigned a null
pointer.
The following does _not_ guarantee that p ends up
with a null pointer...
int i = 0;
void *p = (void *) i;
...for although i is zero valued, it is not a constant
expression.
The representation of a null pointer needn't be all
bits zero. Indeed, there may be many representations
of a null pointer on the same implementation. [I
believe VAX's use to use $A000000 as the null pointer
representation.]
The quality all null pointers (of the same type) have, is
that they compare equal to each other and any null pointer
constant, and they do not compare equal to the address of
an object (or function.)
> then it shows the compilier that it points
> to nothing,
It's better to say that it doesn't point to anything.
> but I thought normally NULL is defined as 0.
Or ((void *) 0) is common in C, though there are many
possibilities. [C++ does not allow NULL to be a pointer.]
It's important to understand that ptr = 0 is syntactic
sugar and treated specially. You can see this quite
easily...
void *p = 0; /* fine: assign null pointer */
void *q = 1; /* constraint violation: int is not
compatible with void * */
--
Peter