Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site redwood.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!hplabs!hpda!fortune!redwood!rpw3 From: rpw3@redwood.UUCP (Rob Warnock) Newsgroups: net.lang.c Subject: Re: String copy idiom. Message-ID: <189@redwood.UUCP> Date: Tue, 12-Mar-85 19:46:57 EST Article-I.D.: redwood.189 Posted: Tue Mar 12 19:46:57 1985 Date-Received: Sat, 16-Mar-85 03:19:01 EST References: <7044@watdaisy.UUCP> <3448@alice.UUCP> <464@petsd.UUCP> Organization: [Consultant], Foster City, CA Lines: 29 Please note that the semantics of while (*s++ = *t++) ; and while ((*s = *t) != '\0') {s++; t++;} are NOT the same; therefore, the generated code CANNOT be the same! (I noticed this while comparing the code generated on the 68000 compiler I use.) The first statement leaves "t" pointing at the byte AFTER the null, while the second leaves "t" pointing to the null. Auto-incrementing cannot be used in the second case, unless your compiler generates code to "back out" the final incrementation (an optimization I have on occasion applied by hand to tight assembly code, but have never seen a compiler use). The following two ARE equivalent (by the definition of "true" in boolean tests and due to the "usual conversions" applied to '\0' before the comparison), and the compiler I use indeed generates the same code for both cases: while (*s++ = *t++) ; and while ((*s++ = *t++) != '\0') ; Rob Warnock Systems Architecture Consultant UUCP: {ihnp4,ucbvax!dual}!fortune!redwood!rpw3 DDD: (415)572-2607 USPS: 510 Trinidad Lane, Foster City, CA 94404