Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!shelby!portia!forel!karish From: karish@forel.stanford.edu (Chuck Karish) Newsgroups: comp.unix.wizards Subject: Re: Referencing NULL pointers Message-ID: <3492@portia.Stanford.EDU> Date: 11 Jul 89 17:29:50 GMT References: <19367@paris.ics.uci.edu> <1891@auspex.auspex.com> <32UP02Eg3d=801@amdahl.uts.amdahl.com> Sender: USENET News System Reply-To: karish@forel.stanford.edu (Chuck Karish) Organization: Mindcrfat, Inc. Lines: 26 In article <32UP02Eg3d=801@amdahl.uts.amdahl.com> vohra@amdahl.uts.amdahl.com (KC) wrote: >In article <1891@auspex.auspex.com> guy@auspex.auspex.com (Guy Harris) writes: [ It's not valid to dereference a NULL pointer ] >Try a rewrite: "x= ((struct somestruct *)0)->somefield". >It can be convenient to make the first page (or whatever unit) >inaccessible to cause errors for structures that are smaller >than that unit. Maybe Sunos does this... >Anyway, it is the operating system that makes the action that the >process takes valid or invalid. Neither the draft C standard nor Kernighan and Ritchie define the format of an executing program. Accessing an arbitrarily-chosen address in memory is thus completely non-portable; there's no way to predict whether 0 is a valid address. The `0' value for NULL is a token with a special meaning, not an address. Whether non-portable usages are `valid' depends on the way the program is to be used. If the program is to have a long life or should be usable on more than one architechure, don't dereference NULL pointers. Chuck Karish {decwrl,hpda}!mindcrf!karish (415) 493-7277 karish@forel.stanford.edu