Assignment in test: OK?
Conor P. Cahill
cpcahil at virtech.uucp
Tue Sep 11 10:31:02 AEST 1990
In article <928 at hls0.hls.oz> george at hls0.hls.oz (George Turczynski) writes:
>In article <BURLEY.90Sep6024459 at world.std.com>, burley at world.std.com (James C Burley) writes:
>> Your code is fine IMHO. But suppose you had written the following
>> accidentally:
>>
>> if (foo = 0)
>>
>> This is a common mistake.
>
>(typing mistake ?)
>
>This is only a mistake if you don't know what you're doing (or you have a
>typo, in which case it's only a mistake for a short while). It is, in fact,
>perfectly legal C, but isn't what people sometimes want it to mean.
This is a BIG mistake because of any and all of the following:
1. you might have made a typo
2. someone else will have to determin if you might
have made a typo
3. If it was a typo, these kinds of problems sometimes don't show
themselves for years and can be the hardest things to debug because
even though there is only a single = there you keep reading the
code and seeing two of them.
The fact that it is legal C doesn't really matter here. That kind of
coding just makes maintenance harder.
--
Conor P. Cahill (703)430-9247 Virtual Technologies, Inc.,
uunet!virtech!cpcahil 46030 Manekin Plaza, Suite 160
Sterling, VA 22170
More information about the Comp.lang.c
mailing list