Referencing NULL pointers

David Goodenough dg at lakart.UUCP
Tue Jul 18 00:58:17 AEST 1989


vohra at uts.amdahl.com (Pavan Vohra) sez:
> I would say that the code is valid.
> 
> Try a rewrite: "x= ((struct somestruct *)0)->somefield".

I have never been comfortable with this construct, and would submit the
following as a "safer" replacement:

	struct somestruct stuff;

	x = (char *) (&stuff.somefield) - (char *) (&stuff);

Comments?????

The above assumes that somefield is not an array: if it is you can take
your pick of:

	stuff.somefield

and:

	&stuff.somefield[0]

-- 
	dg at lakart.UUCP - David Goodenough		+---+
						IHS	| +-+-+
	....... !harvard!xait!lakart!dg			+-+-+ |
AKA:	dg%lakart.uucp at xait.xerox.com		  	  +---+



More information about the Comp.unix.wizards mailing list