Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: $Revision: 1.6.2.16 $; site eel.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!harvard!bbnccv!eel!lee From: lee@eel.UUCP Newsgroups: net.lang.c Subject: Re: Re: how has C bitten you? (Really, Message-ID: <2000002@eel.UUCP> Date: Sun, 1-Sep-85 21:11:00 EDT Article-I.D.: eel.2000002 Posted: Sun Sep 1 21:11:00 1985 Date-Received: Wed, 4-Sep-85 06:27:01 EDT References: <259@watmum.UUCP> Lines: 42 Nf-ID: #R:watmum:-25900:eel:2000002:000:2010 Nf-From: eel!lee Sep 1 21:11:00 1985 One final, subtle, point. K&R does not guarantee that the *value* 0 is distinguishable from all other pointers, but rather, that the *constant* 0 is. That is to say, you may compare against 0 to determine the validity of a pointer (or assign to guarantee invalidity), but you may not assume that comparison against (or assignment of) an int variable whose value is 0 will have the same result. This picky distinction probably doesn't affect any of the better known chips, but might be important on a machine where a null pointer is not a bit string of 0s. While the quotation is true, I think that it refers to the automatic coercion that is required to give the constant 0 the proper distinguishable pattern in the appropriate pointer type. I think we all fairly assume that char *p=0, *q="a"; main() {if (p==q) printf("bogus");} will fail to print because one of the pointers has been assigned the constant 0 and one has been assigned a pointer to a real object. Therefore the value 0 does persist after assignment to any pointer type and is distinguishable from the values in other pointers as well. And two such pointers to the same type both of which have been assigned the value 0 will compare equal. I don't see why the restriction applies to non-pointer variables. As long as type coercions are explicit, this should apply to all values of zero, whether encountered as a literal in the program or as the value of a variable of integral type. I think it is not unreasonable, tho it is certainly not covered anywhere, that coercions between pointers of different types should map the 0 value properly so that, for example, int *p=0; char *q=0; main() {if (p==(int *)q) printf("this is right");} should produce output. We all know that 0 cannot be interpreted as a pointer without knowing what it is a pointer to, but given that we know the types of the pointers involved, the "I don't point to anything" values should be considered equivalent in assignments and comparisons.