Another silly question
Chris Johnson
mesmo at Portia.Stanford.EDU
Thu May 18 06:07:15 AEST 1989
>From article <17812 at cup.portal.com>, by Tim_CDC_Roberts at cup.portal.com:
> Ok, folks. In regards to "a[i] == *(a+i) == *(i+a) == i[a]", let me
> refer to the oft-used example 2["hello"].
> I agree that this works and is equivalent to "hello"[2]. I've seen it
> in books and postings. My simple question is why?
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.
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.
--
==============================================================================
Chris M Johnson === mesmo at portia.stanford.edu === "Grad school sucks rocks"
"Imitation is the sincerest form of plagiarism" -- ALF
==============================================================================
More information about the Comp.lang.c
mailing list