Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!rutgers!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Referencing NULL pointers Message-ID: <10830@smoke.BRL.MIL> Date: 28 Aug 89 03:57:42 GMT References: <32UP02Eg3d=801@amdahl.uts.amdahl.com> <1382@bruce.OZ> <1759@cadillac.CAD.MCC.COM> <10556@smoke.BRL.MIL> <1796@cadillac.CAD.MCC.COM> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 29 In article <1796@cadillac.CAD.MCC.COM> ned%cad@MCC.COM (CME Ned Nowotny) writes: >In article <10556@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn) writes: >>There better not be. C guarantees that valid object addresses compare >>unequal to null pointers, and since a null pointer constant is written >>as "0" in C source code, you cannot obtain a valid object address by >>casting 0 to the object pointer type. >While Chris Torek and you have made good arguments against attempting >to cast a 0 to a valid pointer, I believe you are losing sight of >the distinction between a null pointer represented by the numeric >constant 0 and the address 0 in a given environment. No, in fact I directly addressed the idea of forcing an integral 0 "address" to point at an object. This has nothing to do with whether or not you can obtain useful data from "address" 0 by dereferencing such a pointer. The compiler is entirely at liberty to IMMEDIATELY turn (whatever*)0 into an internal form such as (&__nullity), where __nullity is part of the C library. If you were able to dereference such a "0-valued" pointer, in fact you'd access __nullity, not address 0. Therefore you'd better not have anything at address 0 that really needs to be accessed from C code. >whether there are cases in which valid data resides at location zero in some >systems, including implementations of UNIX, and the question of how to access >it. Original UNIX implementations inserted a "shim" at I-space virtual address 0 to prevent useful data from being allocated there, just to guarantee that null pointers were always distinct from pointers to valid objects.