Path: utzoo!attcan!uunet!munnari.oz.au!uhccux!ames!ucsd!usc!zaphod.mps.ohio-state.edu!tut.cis.ohio-state.edu!purdue!haven!mimsy!mojo!russotto From: russotto@eng.umd.edu (Matthew T. Russotto) Newsgroups: comp.unix.wizards Subject: Re: What machines core dump on deref of NULL? Message-ID: <1990Jul6.152722.5320@eng.umd.edu> Date: 6 Jul 90 15:27:22 GMT References: <13226@smoke.BRL.MIL> <1990Jun29.132304.12550@athena.mit.edu> <418@minya.UUCP> Sender: news@eng.umd.edu (The News System) Organization: College of Engineering, Maryversity of Uniland, College Park Lines: 37 In article <418@minya.UUCP> jc@minya.UUCP (John Chambers) writes: > >And on page 192 of my C bible I find the paragraph: > 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. This > usage is nonportable, and may produce pointers which cause address > exceptions when used. However, it is guaranteed that assignment of > the constant 0 to a pointer will produce a null pointer distinguish- > able from a pointer to any object. > >The trouble with this statement is that I've never seen a C compiler >that implements it. On extant processors, it is simple to prove that >it can't be implemented. If you examine any of the current commercial >processors (68xxx, 8xx86, SPARC, MIPS, PDP11/VAX, etc.), you quickly >learn that all of them have the property that there is no bit pattern >that is guaranteed to cause a fault when used as an address. Why does that statement mean that you can't dereference NULL without a fault? Distinguishable in this sense just means you can use tests like p=0; if (p == &someobject) code(); else othercode() which will always fail (it probably also means that malloc, etc, can never allocate an object at 0) All code which attempts to reference objects at ANY specific memory location (includein kernel code which references interrupt vector tables, etc) will be nonportable-- that is implied by that statement also. -- Matthew T. Russotto russotto@eng.umd.edu russotto@wam.umd.edu ][, ][+, ///, ///+, //e, //c, IIGS, //c+ --- Any questions? Hey! Bush has NO LIPS!