Another silly question
Rob McMahon
cudcv at warwick.ac.uk
Tue May 23 05:36:09 AEST 1989
In article <756 at mccc.UUCP> pjh at 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 at uk.ac.warwick ARPA: cudcv at warwick.ac.uk
Rob McMahon, Computing Services, Warwick University, Coventry CV4 7AL, England
More information about the Comp.lang.c
mailing list