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

Henry Spencer henry at zoo.toronto.edu
Sat Mar 23 03:30:37 AEST 1991


In article <13603 at helios.TAMU.EDU> byron at archone.tamu.edu (Byron Rakitzis) writes:
>a)	while (*foo++ = *bar++)
>b)	while ((*foo++ = *bar++) != 0)
>
>All I can say is, if you code in style (a) rather than style (b), don't
>expect anyone reading your code to enjoy the experience.
>
>Henry, are you behind me on this one? ...

Yes.  Deliberately using a construct that looks like a well-known and subtle
programming error is a mistake.  Your successor, reading your code, should
*never* have to ask himself "is this really right?"; if there is reason for
doubt, either comment the code or change it.

For that matter, my personal opinion is that relying on C's implicit
comparison against zero in conditionals is usually a mistake, barring one
or two special cases like variables that are deliberately used only as
booleans.  That's a broader and more debatable point, though.
-- 
"[Some people] positively *wish* to     | Henry Spencer @ U of Toronto Zoology
believe ill of the modern world."-R.Peto|  henry at zoo.toronto.edu  utzoo!henry



More information about the Comp.lang.c mailing list