Another silly question
Blair P. Houghton
bph at buengc.BU.EDU
Fri May 19 05:15:44 AEST 1989
In article <2336 at Portia.Stanford.EDU> mesmo at Portia.Stanford.EDU (Chris Johnson) writes:
>
> The supposed proof of a[i] == i[a] rests on the faulty
> assumption that (x+y) == (y+x) in all contexts; this is
> not correct.
Oh yeah?
> When "+" denotes simple (ie int/float/etc) arithmetic, the
> operation commutes; when it denotes pointer arithmetic,
> commutation is not legal/meaningful.
>
> The statement that *(a+i) == *(i+a) is therefore invalid.
it implies that you were doing
sometype *a, *i;
something = a[i];
something_else = i[a];
So, like, tell me. When do you use pointers as indices? I.e., if one of
the two variables, a or i, is an int, and the other is a pointer, then
you have leave to say that pointer[int] == int[pointer] because
*(pointer + int) == *(int + pointer) and because
*((pointer or int) + (the other)) == (pointer or int)[the other].
--Blair
"I still think I should be able
to add pointers together."
More information about the Comp.lang.c
mailing list