Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!mips!cs.uoregon.edu!ogicse!intelhf!ichips!iwarp.intel.com!inews!pima!bhoughto From: bhoughto@pima.intel.com (Blair P. Houghton) Newsgroups: comp.lang.c Subject: Re: One more point regarding = and == (more flamage) Message-ID: <3182@inews.intel.com> Date: 22 Mar 91 04:56:34 GMT References: <13603@helios.TAMU.EDU> Sender: news@inews.intel.com Organization: Intel Corp, Chandler, AZ Lines: 30 In article <13603@helios.TAMU.EDU> byron@archone.tamu.edu (Byron Rakitzis) writes: >It's this: There is no way when you see the code-fragment >a) while (*foo++ = *bar++) >to tell whether a copy of data in strcpy fashion is intended, or whether >this should have been a strcmp-like loop: > while (*foo++ == *bar++) >the first instance is rendered UNAMBIGUOUS by the addition: >b) while ((*foo++ = *bar++) != 0) Or by the additions: /* copy bytes till end of string */ while (*foo++ = *bar++) /* compare bytes till there's a difference */ while (*foo++ == *bar++) /* mommy: please hold my hand */ while ((*foo++ = *bar++) != 0) Basically, if you're worth the meager pittance they direct-deposit into your debt with the Company Store, the comments will have existed long before you wrote the code. Put those in, and make them accurate, and it doesn't matter how much the code obfuscates. It's called top-down design, and involves _thinking_ before you start making mistakes. --Blair "Back to basics."