Funny mistake

Antek Laczkowski antek at binoc.tamu.edu
Thu Mar 14 17:08:22 AEST 1991


>>I had a funny mistake the other day you might be interested in. 
>>What I wanted to write was:
>>	if (fct(a,b,c))
>>but by mistake I wrote:
>>	if (fct(a,b),c)

Hell, I have no idea what "fct" is for; but that remains me my mistakes, 
a VERY hard to catch one, because the string (see below) is still perfect 
C code (like that above - no SYNTAX error there!) : 

"if (a = b)" instead of "if (a == b)". 

That's a REALLY disgusting error, 
because the "C" compiler (at least under UNIX BSD 3.4) doesn't report it, 
and the effect is to set "a" to be "b" and the "if" behaves depending of
the value of "b" - well, I can't blame the compiler, it thinks, my idea is
"set a to be b and check, what the value is" - but at least "lint" should 
point it as a possible source of errors. If you have 10000 lines of code and
1000 "ifs" inside, "searching" for "=" or for "if" can make you happy.
A debugger is better - but still... I'm carefull now, but anyway, it happens.

The goal of this post is to point out this particular kind of error, not
to tell everyone around how good in "C" I am - I'm not very good :)

Antek @ Bioch.Tamu.Edu ("reply" won't work - that's a new UNIX system!)



More information about the Comp.lang.c mailing list