Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!decwrl!shelby!bloom-beacon!world!burley From: burley@world.std.com (James C Burley) Newsgroups: comp.lang.c Subject: Re: Assignment in test: OK? Message-ID: Date: 6 Sep 90 09:44:59 GMT References: <1990Sep5.185451.25532@DRD.Com> Sender: burley@world.std.com (James C Burley) Organization: The World Lines: 36 In-Reply-To: mark@DRD.Com's message of 5 Sep 90 18:54:51 GMT In article <1990Sep5.185451.25532@DRD.Com> mark@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, I worry when a heavy duty tool like Saber complains about something. Is this practice considered kosher by those in the know? Why or why not? -- mark@DRD.Com uunet!apctrc!drd!mark$B!J%^!<%/!!!&%m!<%l%s%9!K(B Your code is fine IMHO. But suppose you had written the following accidentally: if (foo = 0) This is a common mistake. My guess is that Saber (which I don't know anything about) 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 like to think a somewhat smarter analysis by Saber would prevent it from worrying, since the assignment expression is a subexpression serving as an operand for a comparison operator. But getting a programmer to look at more things than are real problems is preferable to going the other way; and perhaps Saber just token-analyzes without building expression trees and suchlike. BTW, if I ever write a new C-like language, ":=" will be the assignment operator, "==" the comparison operator, and "=" totally invalid! Although I haven't made that mistake more than twice in the past year, the memories of debugging (without a lint/Saber available) for hours, just to find a case of that common mistake, stay with me... (-: James Craig Burley, Software Craftsperson burley@world.std.com