🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c
Article #6149

Re: a[], *p: if 0 <= p - a < sizeof(a), must p point to an element of a?

#6149
From: Doug Gwyn
Date: Fri, 05 Jan 1990 02:14
13 lines
1110 bytes
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.
Technical Details
Message-ID: <11882@smoke.BRL.MIL>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!zaphod.mps.ohio-state.edu!uakari.primate.wisc.edu!aplcen!haven!adm!smoke!gwyn
References: <875@stealth.acf.nyu.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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