Referencing NULL pointers

Mike Mc Gaughey mmcg at bruce.OZ
Sun Jul 16 12:49:53 AEST 1989


vohra at 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 at bruce.cs.monash.oz

"Danger, Will Robinson, cosmic storm approaching!"
	- in bruce's /vmunix.



More information about the Comp.unix.wizards mailing list