pointer comparison question

steve emmerson steve at umigw.MIAMI.EDU
Mon Nov 14 10:58:26 AEST 1988


Sorry to bring this up again, but I didn't get no satisfaction last time
(i.e. no one responded to the main point in question).

The question is this: is the following expression guaranteed to return 
true if and only if "TestPtr" points within the array:

static struct foo	array[NUM];
static struct foo	BegPtr	= array[0];
static struct foo	BegPtr	= array[NUM-1];
extern struct foo	*TestPtr;				/* could also come from a
											   function call */

TestPtr >= BegPtr && TestPtr <= EndPtr;		/* guaranteed to do what
											   I want? */

Or is it "implementation defined" or "undefined".  Note the "if and only
if" condition, which means that if the expression is false, then "TestPtr" 
*must* point "outside" the array.

I know about pointer comparisons only being guaranteed for pointers into
the same array.  What I don't know is what that means for the above
expression.

P.S.  This is a contrived problem.  I know the alternatives.
-- 
Steve Emmerson                     Inet: steve at umigw.miami.edu [128.116.10.1]
SPAN: miami::emmerson (host 3074::)      emmerson%miami.span at star.stanford.edu
UUCP: ...!ncar!umigw!steve               emmerson%miami.span at vlsi.jpl.nasa.gov
"Computers are like God in the Old Testament: lots of rules and no mercy"



More information about the Comp.lang.c mailing list