Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: $Revision: 1.6.2.16 $; site ISM780.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!think!ISM780!darryl From: darryl@ISM780.UUCP Newsgroups: net.lang.c Subject: Re: Re: how has C bitten you? (Really, Message-ID: <30000012@ISM780.UUCP> Date: Thu, 5-Sep-85 08:20:00 EDT Article-I.D.: ISM780.30000012 Posted: Thu Sep 5 08:20:00 1985 Date-Received: Sat, 7-Sep-85 07:11:17 EDT References: <259@watmum.UUCP> Lines: 37 Nf-ID: #R:watmum:-25900:ISM780:30000012:000:1705 Nf-From: ISM780!darryl Sep 5 08:20:00 1985 >> K&R does not guarantee that the *value* 0 >> is distinguishable from all other pointers, but rather, that the >> *constant* 0 is. >> >> 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. > >As for "why" - think of a machine where a null pointer *didn't* have the >same bit pattern as the integer 0. Every time you assigned an integer to a >pointer, you'd have to check whether the integer was zero or not and assign >a null pointer instead (unless the computation you had to do to convert an >integer to a pointer did this anyway). Exactly, but also consider what K&R says in section 7.14: The compilers currently allow a pointer to be assigned to an integer, an integer to a pointer, and a pointer to a pointer of another type. The assignment is a pure copy operation, with no conversion. Also, in section 14.4: A pointer may be converted to any of the integral types large enough to hold it. [...] The mapping function is also machine dependent, but is intended to be unsurprising to those who know the addressing structure of the machine. Although this does not seal it up completely, it seems that K&R had it in mind that putting pointers into integers (and taking them back again) would have no overhead. Checking for a 0 *value* probably is more overhead than they had in mind. --Darryl Richman, INTERACTIVE Systems Corp. ...!cca!ima!ism780!darryl The views expressed above are my opinions only.