Cryptic C code?

Andrew Koenig ark at alice.UUCP
Mon Aug 12 09:18:21 AEST 1985


      strcpy(s, t)  /* copy t to s; pointer version 3 */
      char *s, *t;
      {
	 while (*s++ = *t++)
	    ;
      }
   
   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?


Yes.

In version 3, I am saying that the character that terminates a string
is the same character is that is the implicit subject of an unstated
comparison in a `while' statement.  In version 2, the string terminator
is an explicitly stated constant.  Viewed that way, the two versions
are equivalent only by coincidence.



More information about the Comp.lang.c mailing list