Indexing vs pointers
Walter Bays
walter at garth.UUCP
Tue May 3 05:12:41 AEST 1988
In article <629 at clinet.FI> msa at clinet.UUCP (Markku Savela) writes:
>In article <587 at vsi.UUCP> friedl at vsi.UUCP (Stephen J. Friedl) writes:
>> strcpy(dst, src)
>> char dst[], src[];
>> {
>> int i;
>>
>> for (i = 0; dst[i] = src[i]; i++)
>> ;
>> }
> 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)?
I think that with a good compiler, for any architecture, you're better off
writing in a simple and straightforward manner. The Clipper compiler will
compile the example above using pointers just as if you had written it
with pointers. The difference is, if the pointers are programmer declared,
they have to be kept around, while if they are compiler generated, the
registers are available for reuse. And of course if you use the library
version (written with specific knowledge of the architecture) it will be
faster still.
--
------------------------------------------------------------------------------
Any similarities between my opinions and those of the
person who signs my paychecks is purely coincidental.
E-Mail route: ...!pyramid!garth!walter
USPS: Intergraph APD, 2400 Geng Road, Palo Alto, California 94303
Phone: (415) 852-2384
------------------------------------------------------------------------------
More information about the Comp.lang.c
mailing list