Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!apple!bloom-beacon!bu-cs!buengc!bph From: bph@buengc.BU.EDU (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: Another silly question Message-ID: <2904@buengc.BU.EDU> Date: 18 May 89 19:15:44 GMT References: <17812@cup.portal.com> <2336@Portia.Stanford.EDU> Reply-To: bph@buengc.bu.edu (Blair P. Houghton) Followup-To: comp.lang.c Organization: Boston Univ. Col. of Eng. Lines: 30 In article <2336@Portia.Stanford.EDU> mesmo@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."