Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!unmvax!bbx!bbxsda!scott From: scott@bbxsda.UUCP (Scott Amspoker) Newsgroups: comp.unix.wizards Subject: Re: What machines core dump on deref of NULL? Message-ID: <838@bbxsda.UUCP> Date: 29 Jun 90 16:54:59 GMT References: <444@mtndew.UUCP> <31079@cup.portal.com> <13226@smoke.BRL.MIL> <412@minya.UUCP> Reply-To: scott@bbxsda.UUCP (Scott Amspoker) Organization: Basis International, Albuquerque, NM Lines: 38 In article <412@minya.UUCP> jc@minya.UUCP (John Chambers) writes: > Such embedded, standalone >programs not only can, but are required to access all of physical >memory, including address zero. The hardware says that something >particular resides at the bottom end of memory, and such a program >must access that byte/word/whatever, or it can't do its job. If a >C compiler won't let me access that address, then I look for another ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ >that was written by someone more competent. Please re-read the thread. We are not talking about a feature of the C compiler but a feature of the host operating system. If you are running a standalone, absolute memory application then such error traps would not apply. >Of course, all C compilers already have a perfectly good tool for >doing a run-time check for a null pointer: > if (p == 0 ) ... >I use it a lot. In particular, I introduce it all over the place >in code that I'm porting from VAXen to other machines. I suggest >that others try it. It's a whole lot nicer than having your program >bomb out on a SEGV. Well, what if p==0? continue? abort? I think posters on this thread were refering to the situations where a null pointer should *not*, by definition, be present. In which case, dereferencing a NULL would indicate a bug that the programmer would wish to discover early in the testing phase. If the pointer in question could not be trusted (i.e. passed by an outside library routine) then it would be prudent to explicitly test it as you have shown. -- Scott Amspoker Basis International, Albuquerque, NM (505) 345-5232 unmvax.cs.unm.edu!bbx!bbxsda!scott