Path: utzoo!attcan!uunet!husc6!mailrus!ames!amdahl!amdcad!crackle!tim From: tim@crackle.amd.com (Tim Olson) Newsgroups: comp.lang.c Subject: Re: pointer comparison question Message-ID: <23537@amdcad.AMD.COM> Date: 14 Nov 88 16:38:10 GMT References: <185@umigw.MIAMI.EDU> Sender: news@amdcad.AMD.COM Reply-To: tim@crackle.amd.com (Tim Olson) Distribution: na Organization: Advanced Micro Devices, Inc. Sunnyvale CA Lines: 30 Summary: Expires: Sender: Followup-To: In article <185@umigw.MIAMI.EDU> steve@umigw.miami.edu (steve emmerson) writes: | 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. It is undefined. The "iff" condition also means that if the expression is true, then "TestPtr" must point *inside* the array, which is the problem here. Section 3.3.8 of the ANSI Draft says: "... If the objects pointed to are not members of the same aggregate or union object, the result is undefined." -- Tim Olson Advanced Micro Devices (tim@crackle.amd.com)