Path: utzoo!attcan!uunet!mcvax!ukc!warwick!cudcv From: cudcv@warwick.ac.uk (Rob McMahon) Newsgroups: comp.lang.c Subject: Re: Another silly question Message-ID: <155@titania.warwick.ac.uk> Date: 22 May 89 19:36:09 GMT References: <17812@cup.portal.com> <607@kl-cs.UUCP> <749@mccc.UUCP> <17635@mimsy.UUCP> <756@mccc.UUCP> Reply-To: cudcv@warwick.ac.uk (Rob McMahon) Organization: Computing Services, Warwick University, UK Lines: 32 In article <756@mccc.UUCP> pjh@mccc.UUCP (Pete Holsberg) writes: >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 ... 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). I'll lay odds that you're comparing int i; for (i = 0; i < MAX; i++) a[i] = 0; with grimble *p; for (p = a; p < &a[MAX]; p++) *p = 0; am I right? Note that this is not comparing `a[i]' with `*(a+i)' at all, the second loop simply has to increment a pointer, not scale an integer and add it to the address of an array. Compilers with strength reduction will make both equivalent. On machines with fiendish indexed addressing modes the first may be as fast or faster, on other machines the second may be faster. Rob -- UUCP: ...!mcvax!ukc!warwick!cudcv PHONE: +44 203 523037 JANET: cudcv@uk.ac.warwick ARPA: cudcv@warwick.ac.uk Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England