Creating pointer with all bits 0 (was: Referencing NULL pointers)

Henry Spencer henry at utzoo.uucp
Thu Sep 7 02:41:25 AEST 1989


In article <1989Sep6.052228.17374 at algor2.algorists.com> jeffrey at algor2.UUCP (Jeffrey Kegler) writes:
>Question: Is an implementation whose null pointer is the same as the
>result of some integer-to-pointer cast conforming?  Apparently not,
>since 3.2.2.3 states, "... a null pointer is guaranteed to compare
>unequal to a pointer to any object or function."

Does not follow.  There is nothing that says that the result of casting
an integer to a pointer will be a pointer to an object.  It is entirely
legitimate for some integers to become null pointers when cast.

>If I am correct, this could cause problems.  It is not hard to imagine
>an implementation where every possible pointer bit pattern is a valid
>physical address.  No pattern would remain for the null pointer...

The pdp11, the very first machine on which C was implemented, had this
property.  The solution was to use a software convention in which no
variable was ever put at location 0, and any programmer who *really*
wanted to use something at 0 was breaking the rules and was on his own.
I see no reason why the same approach won't work for ANSI C.
-- 
V7 /bin/mail source: 554 lines.|     Henry Spencer at U of Toronto Zoology
1989 X.400 specs: 2200+ pages. | uunet!attcan!utzoo!henry henry at zoo.toronto.edu



More information about the Comp.lang.c mailing list