Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ames!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.lang.c Subject: Re: Referencing NULL pointers Message-ID: <10568@smoke.BRL.MIL> Date: 20 Jul 89 23:06:31 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: 23 In article <1796@cadillac.CAD.MCC.COM> ned%cad@MCC.COM (CME Ned Nowotny) writes: >There are byte-addressable systems where important data may reside at >address 0. I think Chris and I know that. What we're saying is, don't attempt to use what appears like an integer constant "0" to construct an access to such a location. Instead, try something like #define word_at(loc) ((int*)(sizeof(int)+(loc))[-1] which will not run afoul of C's null pointer convention. Of course, there may be some C implementations (maybe "Safe C") that perform run-time dereferencing checks, in which case it would be possible that there is no valid way to access address zero directly from C. I doubt that you'd be using such an implementation if you were munging address zero, however. >Other languages do not care whether 0 is a valid address or not. I have no doubt that it would have been preferable to have designed an explicit "nil" keyword into C. For one thing, it would have avoided these endless discussions about dereferencing null pointers! However, as with numerous other "warts", we're stuck with it and merely need to learn how to live with it. For the vast majority of applications it should not pose a problem.