Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!umich!yale!cs.utexas.edu!rutgers!cmcl2!stealth.acf.nyu.edu!brnstnd From: brnstnd@stealth.acf.nyu.edu Newsgroups: comp.std.c Subject: Re: a[], *p: if 0 <= p - a < sizeof(a), must p point to an element of a? Message-ID: <3392@stealth.acf.nyu.edu> Date: 10 Jan 90 00:59:50 GMT References: <875@stealth.acf.nyu.edu> Reply-To: brnstnd@stealth.acf.nyu.edu (Dan Bernstein) Distribution: usa Organization: IR Lines: 14 The answer to the specific question in the subject: No. The standard guarantees nothing; and the test will fail on micros in practice. It may also fail on some real computers if the type is of size 2 or more and if p points between elements of a. The answer to the question of how to reliably test whether p points to an element of a: Run through the elements of a and test each against p. There doesn't seem to be a faster portable method. When ANSI says ``undefined,'' it really does mean that your computer could blow up. This is an unfortunate gap in the standard (though, I admit, not a sufficient incentive to switch to Ada). ---Dan