One more point regarding = and == (more flamage)

Blair P. Houghton bhoughto at pima.intel.com
Fri Mar 22 14:56:34 AEST 1991


In article <13603 at helios.TAMU.EDU> byron at 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."



More information about the Comp.lang.c mailing list