lclint-interest message 3
Date: Mon, 24 Oct 94 15:08:25 -0400
From: evs (David Evans)
Cc: firstname.lastname@example.org, email@example.com
In-Reply-To: firstname.lastname@example.org's message of Mon, 24 Oct 94 11:34:16 -0700 <9410241834.AA11617@roustabout.pa.dec.com>
Subject: improvement on predicates?
>> From: email@example.com (Peter Chang)
>> Re the subject line. I'm not entirely happy with using +boolint (or is
>> it -boolint) to stop lint producing warnings on predicates such as:
>> "if (verbose)". Maybe a check for pure assignments in predicates is
>> needed, eg warn against lines like "if (bar = foo())".
> From: firstname.lastname@example.org
> Dave can check me on this, but I think you can eliminate this problem
> merely by declaring verbose to be a bool, rather than an int, if it is
> intended to be used for logical tests.
> Separately, a check for pure assignments in predicates might be a good
> Jim H.
Yes, if verbose is declared as a bool you will not get an error message
here. If you don't want to declare verbose as a bool here, you can
still supress the error message without making bool and int
indistinguishable in all contexts by using -pred instead.
However, Peter's suggestion that there should be a way to check for
assignments in predicates is probably a good one. For the case,
if (bar = foo())
lclint will report an error if bar is not a bool (unless -pred is used).
But if bar is a bool (and foo returns a bool), lclint with the default
flag settings reports an error (because of bool comparison) for (bar ==
foo()) but not (bar = foo()).
University of Virginia, Computer Science