String copy idiom.
Daniel J. Salomon
djsalomon at watdaisy.UUCP
Sat Mar 9 04:36:17 AEST 1985
> The VAX 4.2 BSD UNIX library routine 'strcpy' uses code equivalent
> to the less efficient sequence: while (*s++ = *t++);
> Perhaps it should be changed.
>
SORRY for this error.
The idiom "while (*s++ = *t++);" generates the fastest possible code
if s and t are declared to be registers, which they are in the
system version of strcpy. But note that if s and t are not in
registers then the sequence:
while (*s = *t) {s++; t++;}
is more efficient.
More information about the Comp.lang.c
mailing list