Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!apple!ames!uhccux!munnari.oz.au!bruce!mmcg From: mmcg@bruce.OZ (Mike Mc Gaughey) Newsgroups: comp.unix.wizards Subject: Re: Referencing NULL pointers Message-ID: <1382@bruce.OZ> Date: 16 Jul 89 02:49:53 GMT References: <32UP02Eg3d=801@amdahl.uts.amdahl.com> Organization: Monash Uni. Computer Science, Australia Lines: 21 vohra@uts.amdahl.com (Pavan Vohra) [11 Jul 89 07:35:39 GMT]: > > I would say that the code is valid. > > Try a rewrite: "x= ((struct somestruct *)0)->somefield". Sure it's valid. It's just that the pointer value you are using does not point to any valid object (like a variable, or some heap space, or writable code) and hence may not point to allocated memory. Result: segmentation violation. If you want to hardwire a particular address, that's up to you - maybe some useful information is there - but don't bitch when it doesn't work on someone else's machine. BTW: There _is_ a way to guarantee that you have a valid pointer - it's called malloc :-) -- Mike McGaughey ACSNET: mmcg@bruce.cs.monash.oz "Danger, Will Robinson, cosmic storm approaching!" - in bruce's /vmunix.