Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!henry From: henry@utzoo.UUCP (Henry Spencer) Newsgroups: net.lang.c Subject: Re: Must a NULL pointer be a 0 bit pattern? Message-ID: <4576@utzoo.UUCP> Date: Sat, 3-Nov-84 19:05:28 EST Article-I.D.: utzoo.4576 Posted: Sat Nov 3 19:05:28 1984 Date-Received: Sat, 3-Nov-84 19:05:28 EST References: <6542@mordor.UUCP> <5272@brl-tgr.ARPA> <196@rlgvax.UUCP>, <529@wjh12.UUCP>, <100@azure.UUCP> Organization: U of Toronto Zoology Lines: 25 > 1. Because of implicit comparison with zero, as in "while(p)s;", this idea > is cannot be implemented simply by changing stdio.h to read > #define NULL ((char*)0x87654321) Quite correct. The compiler itself has to know what the bit pattern of the 0 pointer is, so that it can generate correct code for implicit comparisons against 0. > 2. In making changes to the compiler, this must remain zero: > (p = NULL , (int)p) > Also, for every declared "var", this must remain one: > (p = &var , (int)p != 0) Sorry, wrong. The results of casting a pointer to integer are explicitly implementation-defined, except for the ability -- in certain limited circumstances -- to cast it back to pointer and get the same one you started with. There are *no* *guarantees* anywhere about the results of the comparisons you give, and compilers for odd machines are entitled to give results other than the ones you suggest. The key point in all of this is that the constant 0 does not necessarily have the same representation in all types. -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry