One more point regarding = and == (more flamage)
Byron Rakitzis
byron at archone.tamu.edu
Fri Mar 22 11:46:32 AEST 1991
I have one more thing to say to the self-styled C gods who approve of
simple assignments as an implicit test against zero inside an if-statment.
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++)
One is forced to gather from the context of the program just what the
programmer intended. Now in this case, it may be "obvious" what the
intent of the programmer is, but I don't think anyone can doubt that
the first instance is rendered UNAMBIGUOUS by the addition:
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? What do the coding style people say
anyway?
More information about the Comp.lang.c
mailing list