Article View: comp.std.c
Article #6152Re: a[], *p: if 0 <= p - a < sizeof(a), must p point to an element of a?
From: T. William Wells
Date: Fri, 05 Jan 1990 04:07
Date: Fri, 05 Jan 1990 04:07
17 lines
1161 bytes
1161 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 general, if p does not point to a member of a, p - a is
undefined.
: The standard should define pointer subtraction more carefully.
It has defined this most explicitly. Since my fingers are tired,
I won't type in the appropriate text. But it is in section 3.3.6.
---
Bill { uunet | novavax | ankh | sunvice } !twwells!bill
bill@twwells.com
Technical Details
Message-ID:
<1990Jan5.040710.23691@twwells.com>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!uunet!twwells!billReferences:
<875@stealth.acf.nyu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!cs.utexas.edu!uunet!twwells!bill From: bill@twwells.com (T. William Wells) Newsgroups: comp.std.c Subject: Re: a[], *p: if 0 <= p - a < sizeof(a), must p point to an element of a? Message-ID: <1990Jan5.040710.23691@twwells.com> Date: 5 Jan 90 04:07:10 GMT References: <875@stealth.acf.nyu.edu> Distribution: usa Organization: None, Ft. Lauderdale, FL Lines: 17