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: Re: how has C bitten you? (Really, Message-ID: <5938@utzoo.UUCP> Date: Sat, 7-Sep-85 19:36:12 EDT Article-I.D.: utzoo.5938 Posted: Sat Sep 7 19:36:12 1985 Date-Received: Sat, 7-Sep-85 19:36:12 EDT References: <259@watmum.UUCP>, <30000012@ISM780.UUCP> Organization: U of Toronto Zoology Lines: 33 > 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. Note that they do not say that this is a legitimate feature of the language! All they say is that the current compilers will let you get away with it. This is no longer generally true, by the way. K&R is quite old. > 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.... True, but there is a subtle point here: they say you can convert pointers to (sufficiently large) integers, they may say that you can convert the result back, but they don't say what the integer will look like. A NULL pointer will not necessarily show up as an integer zero. The equality between NULL pointers and 0 works only when 0 is a literal constant, in which case it is (potentially) treated specially by the compiler when encountered in a "pointer" context. The conversion of literal 0 to the NULL pointer is *not* an instance of the general "putting pointers into integers (and taking them back again)" conversion. -- Henry Spencer @ U of Toronto Zoology {allegra,ihnp4,linus,decvax}!utzoo!henry