Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!amdcad!crackle!tim From: tim@crackle.amd.com (Tim Olson) Newsgroups: comp.lang.c Subject: Re: Another silly question Message-ID: <25711@amdcad.AMD.COM> Date: 22 May 89 16:33:02 GMT References: <17812@cup.portal.com> <607@kl-cs.UUCP> <749@mccc.UUCP> <17635@mimsy.UUCP> <756@mccc.UUCP> Sender: news@amdcad.AMD.COM Reply-To: tim@amd.com (Tim Olson) Organization: Advanced Micro Devices, Inc. Sunnyvale CA Lines: 48 Summary: Expires: Sender: Followup-To: In article <756@mccc.UUCP> pjh@mccc.UUCP (Pete Holsberg) writes: | In article <17635@mimsy.UUCP> chris@mimsy.UUCP (Chris Torek) writes: | =In article <749@mccc.UUCP> pjh@mccc.UUCP (Pete Holsberg) writes: | =[in response to article <607@kl-cs.UUCP> by pc@cs.keele.ac.uk (Phil Cornes)] | =>Can you explain why compilers produce different code for "a[i]" and "*(a+i)"? | = | =I have never observed one to do so. There is no reason for a compiler | =to generate different code, as the expressions are semantically identical. | | Perhaps I've asked the wrong question. I saw a couple of simple test | programs that assigned 0 to each member of an array. One used array | subscript notation, and the other, pointer notation. I compiled these | on a 7300, a 3B2/400, and a 386 running Microport V/386, using a variety | of compilers (cc and gnu-cc on the 7300, fpcc on the 3B2, and cc and | Greenhills on the 386). I ran each version and timed the execution. | The subscript versions had different run times from the pointer versions | (some slower, some faster!). I assumed - perhaps naively - that the | differences were caused by differences in code produced by the different | compilers (and of course the hardware differences). Was that wrong? | How does one account for the differences? If you wrote the routines like: int a[MAX]; int a[MAX]; int i; int i; for (i=0; i