Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!shelby!Portia!mesmo From: mesmo@Portia.Stanford.EDU (Chris Johnson) Newsgroups: comp.lang.c Subject: Re: Another silly question Message-ID: <2336@Portia.Stanford.EDU> Date: 17 May 89 20:07:15 GMT References: <17812@cup.portal.com> Sender: Chris Johnson Reply-To: mesmo@Portia.Stanford.EDU (Chris Johnson) Organization: Stanford University Lines: 20 From article <17812@cup.portal.com>, by Tim_CDC_Roberts@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@portia.stanford.edu === "Grad school sucks rocks" "Imitation is the sincerest form of plagiarism" -- ALF ==============================================================================