Pointers vs. Arrays: an aside about efficiency
Geoff Kuenning
geoff at desint.UUCP
Tue Oct 9 16:18:49 AEST 1984
>>for maximum efficiency, I have to write:
>> { struct foo *foop = fooarr;
>> for (i=0, i < FOOMAX; i++)
>> dostuff(*(foop++));
>> }
>>instead of what I mean:
>> for (i=0; i < FOOMAX; i++)
>> dostuff(fooarr[i]);
>>
>> Roger Hayes
>Only on some machines does the former generate better code....On some
>machines, pointer handling (other than just plain indirection) is so
>cumbersome that the second piece of code is always better.
> Kevin Martin
Which is precisely the point. The programmer writing the code can't know
what the most efficient method is; the compiler can, and should take
advantage of this knowledge to produce better code.
Of course, we could always put in #if vax || prime || ... :-)
--
Geoff Kuenning
First Systems Corporation
...!ihnp4!trwrb!desint!geoff
More information about the Comp.lang.c
mailing list