Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site brl-tgr.ARPA Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!godot!harvard!seismo!brl-tgr!ron From: ron@brl-tgr.ARPA (Ron Natalie ) Newsgroups: net.lang.c Subject: Re: String copy idiom. Message-ID: <9421@brl-tgr.ARPA> Date: Thu, 21-Mar-85 17:45:54 EST Article-I.D.: brl-tgr.9421 Posted: Thu Mar 21 17:45:54 1985 Date-Received: Sat, 23-Mar-85 01:18:42 EST References: <7042@watdaisy.UUCP> <7044@watdaisy.UUCP> <7047@watdaisy.UUCP> <366@ccice6.UUCP> Distribution: net Organization: Ballistic Research Lab Lines: 18 > Beware of saying things like "the fastest possible". > I found a better way for for any string longer than two characters. > The following is from 4.2BSD on a VAX. > > main() > { > register char *s, *d; > while( *d++ = *s++ ); /* ok */ > if (*d) do {} while ( *d++ = *s++ ); /* <-- FAST -- */ > } > Beware of posting solutions that don't work. If *d == 0 you don't copy anything at all. I'm not quite sure why you put the test in, all it does is make the loop dependent on whats in the destination string before you copy into it. -Ron