Pointers and Arrays (was: C machine)
News system
news at ism780c.UUCP
Tue Feb 2 10:08:36 AEST 1988
I got lost in all the >'s
I (Marv Rubinstein) wrote:
BTW, the definition of pointer difference in K&R is "if p and q point to
members of the same array , p-q is the number of elements between p and q."
Some one else wrote:
>I opened up my K&R, skimmed all of chapter 5 (Pointers and Arrays), and could
>not find this anywhere! (Maybe I didn't look hard enough :-)) I don't think
>this is how K&R defined it (see more comments below).
You didn't :-) Perhaps you should have looked in the index first. In the
index on page 226 one finds the entry:
"pointer subtraction 98"
On page 98 one finds in the last paragraph:
"Pointer subtraction is also valid: if p and q point to members
of the same array , p-q is the number of elements between p and q."
My reason for bring up this whole issue was to point out the the term
"between" used here is fuzzy and could lead one to confusion. I was just
asking if the language in the standard was less ambigious. (Doug answered
that it is less ambigious). Also I once had to correct a compiler that was
implemented such that p-q was the same as q-p (p and q pointers to the same
array). When I found the wording on page 98 I asked several colleagues "how
many integers are there between 1 and 3 and how many integers are there
between 3 and 1?" most answered "one" to both questions.
Marv Rubinstein. -- Interactive Systeme
More information about the Comp.lang.c
mailing list