%p and different pointer representations

Doug Gwyn gwyn at smoke.BRL.MIL
Fri Mar 3 00:25:03 AEST 1989


In article <248 at harrier.ukc.ac.uk> mtr at ukc.ac.uk (M.T.Russell) writes:
>In article <9730 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
>>A function pointer may well not fit into a void*.
>This presumably implies that comparison and assignment between function
>pointers and void* pointers is illegal, and thus that
>	f = NULL;
>and
>	if (f == NULL)
>are both illegal if f is a function pointer and NULL is defined as (void *)0.
>If this is so, then I don't see that (void *)0 is a reasonable definition
>of NULL.
>Is (void *)0 a special case?  Gcc 1.32 -ansi -pedantic doesn't think so -
>it objects to the above constructs.

Yes, null pointer constants are special cases.  (void*)0 is not really
a pointer of type void*, it's just one way of writing a null pointer
constant and thus has special properties.  In particular it can be
assigned to ANY non-const pointer variable and compared against ANY
pointer type.  It compares unequal to a pointer to any object or function.
A valid pointer expression of any type has a value that fits exactly one
of the following categories:
	(1) valid pointer to object or function
	(2) null pointer
An uninitialized static-duration pointer variable starts out with a value
that is a null pointer; other pointer variables acquire null-pointer
values only by having one assigned to them, either directly as a null
pointer constant or indirectly via some other null-valued variable.

GCC 1.32 sounds broken here.



More information about the Comp.lang.c mailing list