Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!apple!agate!eos!jbm From: jbm@eos.UUCP (Jeffrey Mulligan) Newsgroups: comp.unix.wizards Subject: Invalid Pointers (was Re: Referencing NULL pointers) Message-ID: <4348@eos.UUCP> Date: 16 Jul 89 20:44:47 GMT References: <20245@adm.BRL.MIL> Organization: NASA Ames Research Center, California Lines: 45 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; struct foobar *get_a_foobar() { if( can_allocate_memory_and_initialize ) return( a_pointer_to_a_foobar ); else return( NO_FOOBAR ); } /* somewhere else */ if( fb1==NO_FOOBAR ) /* initial state */ if( (fb1=get_a_foobar()) == NO_FOOBAR ) complain_loudly(); So, the question is, how should NO_FOOBAR be defined? #define NO_FOOBAR ((struct foobar *) -1 ) is what I use, but... I note that malloc(3) returns NULL (0) on failure [on the sun], indicating that 0 could never be a valid address returned from malloc. Sorry if this is the wrong newsgroup. -- Jeff Mulligan (jbm@aurora.arc.nasa.gov) NASA/Ames Research Ctr., Mail Stop 239-3, Moffet Field CA, 94035 (415) 694-6290