Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!rutgers!apple!ames!ncar!tank!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.lang.c Subject: Re: Another silly question Message-ID: <17580@mimsy.UUCP> Date: 18 May 89 05:04:53 GMT References: <17812@cup.portal.com> <2336@Portia.Stanford.EDU> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 22 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. When "+" denotes simple (ie int/float/etc) >arithmetic, the operation commutes; when it denotes pointer >arithmetic, commutation is not legal/meaningful. The latter assertion is exactly backwards. Pointer arithmetic (in the forms pointer+integer and integer+pointer) is guaranteed to be commutative, while scalar addition is not: scalar addition of certain values is not commutative on certain peculiar architectures---things like negative zero or peculiar floating point values, for instance. >The statement that *(a+i) == *(i+a) is therefore invalid. Since pointer arithmetic is commutative, the above statement is wrong, and *(a+i) is equivalent to *(i+a), so that a[i] and i[a] denote the same object. See K&R (either edition) chapter 5. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris