Indexing vs pointers

Michael Ryan miker at wjvax.UUCP
Fri May 6 06:30:03 AEST 1988


In article <629 at clinet.FI>, msa at clinet.FI (Markku Savela) writes:
> In article <587 at vsi.UUCP> friedl at vsi.UUCP (Stephen J. Friedl) writes:
> >Let's put this goto business in perspective:
[ ... ]
> >		for (i = 0; dst[i] = src[i]; i++)
> >			;
[ .. ]
> 	I don't!  I'm actually using similar loops in my C-programs
> that are written for MS-DOS machines.  Just try compiling the above
[ ..]
> 	Compare the results (in ASM). Believe or not, the variant
> using indexes is much more compact than the one using pointers (and
> saying "register i" improves it even more...)


ok , far char type/size objects this works swell. but chars are not an 
interesting pointer case!

if , for instance, you have a struct of , say , 60 bytes or so,  like this:

	struct foo {
		char name [ 32 ];
		long value;
		int asst[ 5 ];
	}/**/

	struct foo dave[ 200 ];

accessing dave with indexes becomes harrowing if your compiler is not smart
I currently use , much to my chagrin, Msoft 5.0. an index like dave[3]
becomes

	mov	ax,  02EH ; or there about..
	imul	3	  ; 
	....

excuse the mistakes, this is just an ex. to do anything interesting , meaning
multiple struct access, becomes an exercise in integer multiplication.

no, the Msoft 5.0 optimizer does nothing to change multiple array index
accesses into pointer accesses. why ? I do not know.

a million excuses to any compiler that does index/pointer optimization.
our VAX cc doesn't while our Integrated Solutions cc does.

can anyone name an MS-DOS product that does ?

if one does not know the intelligence of one's compiler I recommend
avoiding indexes, unless one has a great deal of time and don't we all.

-- 
====	*michael j ryan
	*{..!pyramid,..!decwrl!qubix}!wjvax!miker
	*Watkins-Johnson Co., San Jose CA : (408) 435 1400 x3079
	* above views are not necessarily those of Watkins-Johnson Co.



More information about the Comp.lang.c mailing list