Indexing vs pointers
Walter Bright
bright at Data-IO.COM
Thu May 5 04:04:07 AEST 1988
In article <624 at garth.UUCP< walter at garth.UUCP (Walter Bays) writes:
<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(char *dst, char *src)
<<< { int i;
<<< for (i = 0; dst[i] = src[i]; i++) ;
<<< }
<< 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.
With many optimizers, live range analysis is done. What this is is determining
the sections of code where a variable is used (is 'live'). Therefore,
two variables with live ranges that do not overlap can share the same
register. The Datalight and Zortech optimizers do this (I know because I
wrote them!).
I agree with the point that code should be written in a straightforward
manner and let the optimizer 'tune' it for a particular architecture.
Compilers in general are getting good enough to rely on this.
More information about the Comp.lang.c
mailing list