Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!wugate!uunet!algor2.algorists.com!jeffrey From: jeffrey@algor2.algorists.com (Jeffrey Kegler) Newsgroups: comp.lang.c Subject: Re: Creating pointer with all bits 0 (was: Referencing NULL pointers) Message-ID: <1989Sep6.200610.23566@algor2.algorists.com> Date: 6 Sep 89 20:06:10 GMT References: <1989Aug31.052756.18524@sq.sq.com> <2030@se-sd.NCR.COM> <1989Sep6.052228.17374@algor2.algorists.com> <10947@smoke.BRL.MIL> Reply-To: jeffrey@algor2.UUCP (Jeffrey Kegler) Organization: Algorists, Inc. Lines: 40 In article <10947@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: >In article <1989Sep6.052228.17374@algor2.algorists.com> jeffrey@algor2.UUCP (Jeffrey Kegler) writes: >>If I am correct, this could cause problems. It is not hard to imagine >>an implementation where every possible pointer bit pattern is a valid >>physical address. No pattern would remain for the null pointer. > >I've already explained how an implementation could provide a null >pointer anyway, by using a datum in the run-time library whose address >would be used for null pointers. Sorry to have missed the original explanation. I watch for Doug's postings, but this one of his clarifications slipped by me. Followup question: Must the dummy datum above be handled in some way (such as preceding it with another dummy) that guarantees it is not one past the end of any array? It makes sense to me that it should, but the standard does not seem to require this of a conforming implementation. The standard guarantees the pointer to an object will not compare equal to the null pointer (3.2.2.3), but is the pointer one past the end of the array a pointer to an object? Not, IMHO, by the definition of object in 1.6. The situation where a loop incrementing a pointer through an array contains a test of that pointer against the null pointer must be reasonably familiar to Classic C programmers. (The test against the null pointer might be to test for uninitialized pointers, or some error condition might set the pointer to null.) Must the special case of the pointer one past the end of the array being compared to the null pointer be guarded against to be strictly conforming? Again, yes, as far as I can discern. The standard requires that arithmetic with a pointer one past the end of an array not overflow (3.3.6), and suggests that this be implemented by there actually being a physical object at that place (Footnote 43) but does not seem to require such an object. -- Jeffrey Kegler, Independent UNIX Consultant, Algorists, Inc. jeffrey@algor2.ALGORISTS.COM or uunet!algor2!jeffrey 1762 Wainwright DR, Reston VA 22090