Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!rutgers!njin!princeton!njsmu!mccc!pjh From: pjh@mccc.UUCP (Pete Holsberg) Newsgroups: comp.lang.c Subject: Re: Another silly question Message-ID: <756@mccc.UUCP> Date: 21 May 89 16:22:46 GMT References: <17812@cup.portal.com> <607@kl-cs.UUCP> <749@mccc.UUCP> <17635@mimsy.UUCP> Reply-To: pjh@mccc.UUCP (Pete Holsberg) Organization: The College On The Other Side of U. S. Route 1 Lines: 26 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? -- Pete Holsberg, Mercer County Community College, Trenton, NJ 08690 {backbone}!rutgers!njin!princeton!njsmu!mccc!pjh