Assignment in test: OK?
George Turczynski
george at hls0.hls.oz
Mon Sep 10 09:07:18 AEST 1990
In article <1990Sep5.185451.25532 at DRD.Com> mark at DRD.Com (Mark Lawrence) writes:
>
> I have a proclivity to code like the following:
>
> if( (status = FuncCall(foo, bar, gex)) < SomeValue)
> GripeAboutIt();
>
> or variations thereof. When I run saber on such code, it babbles a
> warning about the assignment in the test. Being the gullible naif I am,
> ...
Oh, it babbles does it ? What does it babble ? In future it would be
more useful to know what the warning is about, rather than have someone
tell you what their `opinion' of your code is. Opinions mean very little.
I might "guess" that perhaps Saber complains because the variable type
of `status' and the return type of `FuncCall()' are different. In that
case you may have omitted a vital header file or not performed a necessary
CAST. Who knows ?
Now ...
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.
> ...... is just trying to get you to look at ifs containing assignments, just
> in case you meant to say "if (foo == 0)". In your particular example, I'd
Does Saber warn you that you might have mispelt a variable name ? I doubt
it. It should only bother you with DEFINITE problems or things that it is
unsure about. Lint is for finding out more detailed, obscure and discrete
problems.
> BTW, if I ever write a new C-like language, ":=" will be the assignment
> operator, "==" the comparison operator, and "=" totally invalid! Although
I will be very cautious of such a language.
--
| George P. J. Turczynski. |----------------------------------------------------
| Computer Systems Engineer. | ACSnet: george at highland.oz | I can't speak for the |
| Highland Logic Pty. Ltd. | Phone: +61 48 683490 | company, I can barely |
| Suite 1, 348-354 Argyle St | Fax: +61 48 683474 | speak for myself... |
| Moss Vale. NSW. Australia. 2577 |----------------------------------------------------
More information about the Comp.lang.c
mailing list