Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Path: utzoo!linus!decvax!cca!ima!inmet!bobo
From: bobo@inmet.UUCP
Newsgroups: net.lang.c
Subject: Re: Pointers vs. Arrays: an aside about - (nf)
Message-ID: <1708@inmet.UUCP>
Date: Fri, 5-Oct-84 01:07:24 EDT
Article-I.D.: inmet.1708
Posted: Fri Oct  5 01:07:24 1984
Date-Received: Sat, 6-Oct-84 06:12:13 EDT
Lines: 33

#R:watmath:-922400:inmet:5000024:000:1238
inmet!bobo    Oct  3 13:23:00 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
>----------

I think the point of the strength reduction optimization here is the
removal of the implicit multiplication in the array reference. Now
if the length of "foo" happened to be a power of two and the compiler
was moderately smart you might get a shift. In the general case, however,
replacing the multiplication within the loop with the addition should 
outweigh any extra pointer handling stuff.
				    Mark Friedman
				    Intermetrics, Inc.
				    ...harpo!inmet!bobo
				    ...esquire!inmet!bobo
				    ...ima!inmet!bobo