[net.micro.68k] Infrequency of integer multiplies

lat@druil.UUCP (TepperL) (06/25/85)

It has been pointed out that multi-dimensional arrays will cause
integer multiplies to be implicitly performed, but that most
programs do not use multi-dimensional arrays, so that it
would be OK to not use them.

But what about arrays of structures?  These too will cause implicit
multiplies when referenced as below:

	blotto[i].xyzzy = 21;

I know, I know, in C you should assign a structure pointer to
&blotto[i] and all that, but not everyone writes code that way,
and shouldn't have to either.

Significant or not, you will find arrays like these a lot more
often.
-- 
Larry Tepper	    {ihnp4 | allegra}!druil!lat		+1-303-538-1759

guy@sun.uucp (Guy Harris) (06/26/85)

> But what about arrays of structures?  These too will cause implicit
> multiplies when referenced as below:
> 
> 	blotto[i].xyzzy = 21;
> 
> I know, I know, in C you should assign a structure pointer to
> &blotto[i] and all that,

Besides, computing &blotto[i] and assigning it to a pointer *still* requires
a multiplication; it merely means that if you manipulate several elements of
blotto[i] in a row, or perform several operations on blotto[i].xyzzy, or
both, you can do the computation once and reuse the result.

If you're cycling through the array "blotto", a strength reduction will
(again) eliminate the multiplication (the compiler would also have to do the
trick of saving &blotto[i] in a pointer for you).

I've seen exactly that sort of code in something that at least purported to
be generated by DEC's PDP-11 Fortran IV compiler (not F4P, but the threaded
code compiler - it was a binary of "zork").

	Guy Harris