Indexing vs pointers

Markku Savela msa at clinet.FI
Thu Apr 28 02:48:30 AEST 1988


In article <587 at vsi.UUCP> friedl at vsi.UUCP (Stephen J. Friedl) writes:
>
>Let's put this goto business in perspective:
>
>	/*
> 	 * strcpy() - written by John Doe
>	 */
>	strcpy(dst, src)
>	char	dst[], src[];
>	{
>	int	i;
>
>		for (i = 0; dst[i] = src[i]; i++)
>			;
>	}
>
>     Who objects to this?

	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
code and a variation using pointers with LARGE MEMORY MODEL!

	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...)

	The question is of course: is there really any penalty in
using indexed versions with other architectures (like motorola)?

--
markku savela,   msa at clinet.fi



More information about the Comp.lang.c mailing list