Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn) Newsgroups: comp.std.c Subject: Re: a[], *p: if 0 <= p - a < sizeof(a), must p point to an element of a? Message-ID: <11882@smoke.BRL.MIL> Date: 5 Jan 90 02:14:37 GMT References: <875@stealth.acf.nyu.edu> Reply-To: gwyn@brl.arpa (Doug Gwyn) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 13 In article <875@stealth.acf.nyu.edu> brnstnd@stealth.acf.nyu.edu (Dan Bernstein) writes: >Basically, I want to have a guaranteed test of whether p points to an >element of a, with foo a[N] and foo *p. I know that *if* p points to an >element of a, *then* 0 <= p - a < sizeof(a); is the reverse true? (If >yes, please explain the logic.) No, in fact no strictly conforming program could rely on the converse since p-a would be an illegal operation when p didn't point into a[] (or just past its last element). >The standard should define pointer subtraction more carefully. I think it was pretty darn careful.