Invalid Pointers (was Re: Referencing NULL pointers)

Paul De Bra debra at alice.UUCP
Mon Jul 17 23:46:32 AEST 1989


In article <4348 at eos.UUCP> jbm at eos.UUCP (Jeffrey Mulligan) writes:
}
}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?
}...
}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.

According to the (new) K&R book NULL (0) is indeed guaranteed not to be
a valid data (or text or stack) address.
Furthermore, the only meaningful comparisons between pointers are
comparison between pointers to elements of the same string and comparison
between a pointer and NULL.

Paul.
-- 
------------------------------------------------------
|debra at research.att.com   | uunet!research!debra     |
------------------------------------------------------



More information about the Comp.unix.wizards mailing list