Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site ulysses.UUCP Path: utzoo!watmath!clyde!burl!ulysses!ggs From: ggs@ulysses.UUCP (Griff Smith) Newsgroups: net.lang.c Subject: Re: String copy idiom. Message-ID: <10016@ulysses.UUCP> Date: Fri, 8-Mar-85 21:56:09 EST Article-I.D.: ulysses.10016 Posted: Fri Mar 8 21:56:09 1985 Date-Received: Sun, 10-Mar-85 04:59:20 EST References: <7042@watdaisy.UUCP> Organization: AT&T Bell Laboratories, Murray Hill Lines: 107 1) I don't think the second idiom is any clearer. 2) On my VAX compiler, the code for the "easier to read" idiom is worse than that for the compact one. The only advantage of the long-winded idiom is that it doesn't change much if you neglect to declare register variables; it's a bit slow either way. The following test cases show the difference: ----- test(osp, isp) char *osp, *isp; { register char *ra, *rb; char *ma, *mb; ra = osp; rb = isp; /* case 1, register pointers */ while (*ra++ = *rb++); /* assembly code L16: movb (r10)+,(r11)+ jeql L17 jbr L16 L17: */ ma = osp; mb = isp; /* case 2, memory pointers */ while (*ma++ = *mb++); /* assembly code L18: movl -8(fp),r0 incl -8(fp) movl -4(fp),r1 incl -4(fp) movb (r0),(r1) jeql L19 jbr L18 L19: */ ra = osp; rb = isp; /* case 3, register pointers, "easy to read" loop */ while ((*ra = *rb) != '\0') { ra++; rb++; } /* assembly code L20: movb (r10),(r11) jeql L21 incl r11 incl r10 jbr L20 L21: */ ma = osp; mb = isp; /* case 4, memory pointers, "easy to read" loop */ while ((*ma = *mb) != '\0') { ma++; mb++; } /* assembly code L22: movb *-8(fp),*-4(fp) jeql L23 incl -4(fp) incl -8(fp) jbr L22 L23: */ } -- Griff Smith AT&T Bell Laboratories, Murray Hill Phone: (201) 582-7736 Internet: ggs@ulysses.uucp UUCP: ulysses!ggs ( {allegra|ihnp4}!ulysses!ggs )