Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!ginosko!uunet!mcsun!ukc!edcastle!aiai!richard From: richard@aiai.ed.ac.uk (Richard Tobin) Newsgroups: comp.lang.c Subject: Re: Creating pointer with all bits 0 (was: Referencing NULL pointers) Message-ID: <864@skye.ed.ac.uk> Date: 11 Sep 89 13:41:29 GMT References: <1989Aug31.052756.18524@sq.sq.com> <2030@se-sd.NCR.COM> <1989Sep6.052228.17374@algor2.algorists.com> <10816@riks.csl.sony.co.jp> Reply-To: richard@aiai.UUCP (Richard Tobin) Organization: AIAI, University of Edinburgh, Scotland Lines: 29 ]]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." ] ]This looks like a bit of a problem all right. Can it still be fixed ]by editorial change? For example, "... any legally created object or ]function" or "... any C object or function." I would have thought the right solution to this was for there to be no guarantee that the result of an arbitrary integer-to-pointer cast be an "object or function". Indeed, I believe this is the case: 3.3.4 says "An arbitrary integer may be converted to a pointer. The result is implementation-defined." In a "reasonable" implementation, casting a geuine pointer to an integer and back again will result in the same pointer, so it certainly won't compare equal to zero. Casting other integers to pointers should only be done when you know enough about the machine and compiler you are using. [Please, no flames about casting pointers to integers. I know it's not guaranteed to do anything useful, but it does on all the machines I care about, and has completely reasonable uses.] -- Richard -- Richard Tobin, JANET: R.Tobin@uk.ac.ed AI Applications Institute, ARPA: R.Tobin%uk.ac.ed@nsfnet-relay.ac.uk Edinburgh University. UUCP: ...!ukc!ed.ac.uk!R.Tobin