On Wed, 4 Jan 2012, Chuck Guzis wrote:
And the number of times that I've seen the = used
in C conditionals
instead of == is amazing. I note that many writers have adopted the
"if ( constant == expression)" form rather than the somewhat more
intuitive "if ( expression==constant)" just to catch this kind of
error.
Prob'ly the single most common error by C writers.
Followed by accidental inclusion of a semi-colon after a condition:
while (3 > X);
{ . . .
There's almost always at least one student asking, "Then why doesn't the
compiler prevent it?"
My answer is, "A GOOD compiler might give you a WARNING, for which you
should be grateful. But, it should never PREVENT suspicious code, because
you might WANT to write something like while (*T++ = *S++); "
Say what you want about FORTRAN, but the .EQ.
conditional test could
never be mistaken for an assignment.
Like the arrow for assignment in APL, some languages have things that
others should learn from!
When I first saw the BASIC
conditional of = for equality testing, I told myself "There's going
to be trouble there."
Yep!
--
Grumpy Ol' Fred cisin at
xenosoft.com