Invalid Pointers (was Re: Referencing NULL pointers)

Barry Shein bzs at bu-cs.BU.EDU
Mon Jul 17 12:57:32 AEST 1989


From: jbm at eos.UUCP (Jeffrey Mulligan)
>It has been pointed out that there should be no assumptions
>about what addresses are valid; is there any way to get
>a guaranteed INVALID address?
>
>I commonly do this sort of thing:
>
>struct foobar { /* some stuff */};
>
>static struct foobar *fb1=NO_FOOBAR;

>...

>So, the question is, how should NO_FOOBAR be defined?
>
>#define NO_FOOBAR ((struct foobar *) -1 )	is what I use, but...

A perfectly good solution is:

	struct foobar no_foobar;
	#define NO_FOOBAR (&no_foobar)

being as no_foobar will be the only thing assigned this address it is
unique and solves your problem. This of course works for your example
where you test for a return value of NO_FOOBAR, doing it by causing a
signal to occur (eg. SEGV) is another problem entirely.
-- 
	-Barry Shein

Software Tool & Die, Purveyors to the Trade
1330 Beacon Street, Brookline, MA 02146, (617) 739-0202
Internet: bzs at skuld.std.com
UUCP:     encore!xylogics!skuld!bzs or uunet!skuld!bzs



More information about the Comp.unix.wizards mailing list