Path: utzoo!attcan!uunet!auspex!guy From: guy@auspex.auspex.com (Guy Harris) Newsgroups: comp.lang.c Subject: Re: Another silly question Message-ID: <1657@auspex.auspex.com> Date: 20 May 89 04:49:25 GMT References: <17812@cup.portal.com> <607@kl-cs.UUCP> <749@mccc.UUCP> Reply-To: guy@auspex.auspex.com (Guy Harris) Organization: Auspex Systems, Santa Clara Lines: 25 >Can you explain why compilers produce different code for "a[i]" and "*(a+i)"? If the compiler doesn't produce equally good code for those two cases, it's because the compiler writer wasn't doing as good a job as s/he could. If it produces different but equally good code, I dunno; possibly because the compiler writer didn't understand that "a[i]" is equivalent to "*(a+i)", or decided for whatever reason to implement them differently. The existence of compilers that produce different code for those cases does not, in any way, prove that the two expressions are in equivalent; K&R First Edition points out that ...The expression E1[E2] is identical (by definition) to *((E1)+(E2)). and the December 7, 1988 ANSI C draft says that ...The definition of the subscript operator [] is that E1[E2] is identical to *(E1+(E2))). so further discussion on whether they're equivalent in C is pointless - they are, and that's that. If somebody wants to debate whether they *should* be equivalent, they can, but they're then talking about D or P, say, not C.