Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!apple!oliveb!bu-cs!bzs From: bzs@bu-cs.BU.EDU (Barry Shein) Newsgroups: comp.unix.wizards Subject: Re: Invalid Pointers (was Re: Referencing NULL pointers) Message-ID: <34785@bu-cs.BU.EDU> Date: 17 Jul 89 02:57:32 GMT References: <20245@adm.BRL.MIL> <4348@eos.UUCP> Organization: Boston U. Comp. Sci. Lines: 34 In-reply-to: jbm@eos.UUCP's message of 16 Jul 89 20:44:47 GMT From: jbm@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@skuld.std.com UUCP: encore!xylogics!skuld!bzs or uunet!skuld!bzs