Invalid Pointers (was Re: Referencing NULL pointers)

Jeffrey Mulligan jbm at eos.UUCP
Mon Jul 17 06:44:47 AEST 1989


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 at aurora.arc.nasa.gov)
	NASA/Ames Research Ctr., Mail Stop 239-3, Moffet Field CA, 94035
	(415) 694-6290



More information about the Comp.unix.wizards mailing list