Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 (Tek) 9/28/84 based on 9/17/84; site tektools.UUCP Path: utzoo!linus!philabs!prls!amdimage!amdcad!decwrl!decvax!tektronix!daemon!tektools!bobc From: bobc@tektools.UUCP (Bob Crane) Newsgroups: net.lang.c Subject: Cryptic C code? Message-ID: <359@tektools.UUCP> Date: Thu, 8-Aug-85 20:22:23 EDT Article-I.D.: tektools.359 Posted: Thu Aug 8 20:22:23 1985 Date-Received: Mon, 12-Aug-85 05:38:10 EDT Distribution: net Organization: Tektronix, Beaverton OR Lines: 42 I was looking through the book, _The C Programming Language_, and came across something very disturbing. In chapter 5, pg. 101 it says: As the final abbreviation, we again observe that a comparison against \0 is redundant, so the function is often written as strcpy(s, t) /* copy t to s; pointer version 3 */ char *s, *t; { while (*s++ = *t++) ; } Although this may seem cryptic at first sight, the notational convenience is considerable, and the idiom should be mastered, if for no other reason than that you will see it frequently in C programs. Yeaacch!!!!!! It was still very cryptic to me the tenth time that I read it!!! A friend explained it to me by saying that the character in the 'while' expression is converted to an int and that the NULL character has an ascii value of 0 so the test will exit when the NULL character is encountered. I have trouble believing that the above has advantages of great speed OR readability over: strcpy(s,t) /* copy t to s; pointer version 2 */ char *s, *t; { while ((*s++ = *t++) != '\0') ; } Does anyone out there support the author by saying that Version 3 of 'strcpy' is better than Version 2? Bob Crane !tektronix!tektools!bobc (503)627-5379