Pointers vs. Arrays: an aside about efficiency

Kevin Martin kpmartin at watmath.UUCP
Mon Oct 1 03:14:05 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. Even on a Vax,
for some storage class and type combinations, the amount of code would
be the same (but the former might run *slower* cuz it is incrementing
two variables each time around the loop). On some machines, pointer handling
(other than just plain indirection) is so cumbersome that the second piece
of code is always better.
                 Kevin Martin, UofW Software Development Group



More information about the Comp.lang.c mailing list