Messages in this thread | | | Date | Thu, 6 May 1999 01:33:26 -0400 (EDT) | From | Steve Willer <> | Subject | RE: fork() Problem? |
| |
On Wed, 5 May 1999, Richard B. Johnson wrote:
> Lint _clearly_ states that it's an error.
Lint calls anything "suspicious" an error, whether it violates the language definition or not.
> Further, previous text states why. Any time I point out these things > I get a bunch of fanatical "tool gurus" responding that I don't > know what I'm talking about.
You don't. You're trying to equate policy and specifications. They're not the same thing. It is not a "compiler bug" if the compiler behaves according to spec. If you don't like that coding practice, that's a policy.
> That said, the problem with: > > if(a=b) > > is that the value of a is not tested. 'a' got assigned the value of > 'b', but only the assignment was tested, not the resulting value.
The resulting value is in fact the result of the assignment test.
> This, as I explained over and over again, is called a > "boolean test of assignment error". It is a real error because,
It's not a boolean. The result of the "a=b" expression is whatever type "a" is. The result of the expression is being used in a boolean manner, but it is not in fact boolean.
> unless the machine crashed, it is always TRUE. This is what > Lint is complaining about. One needs to test the result. You > can do this by adding a sequence-point.
I did this just now:
willer@anzha:~$ cat >test.c #include <stdio.h> int main() { int a; int b; b = 1; if (a=b) printf("first expression succeeded\n"); b = 0; if (a=b) printf("second expression succeeded\n"); } willer@anzha:~$ gcc test.c -o test willer@anzha:~$ ./test first expression succeeded
Perhaps you could point out a compiler that behaves the way you were expecting?
Take a look again at the Lint errors:
xxx.c: (in function main) xxx.c:13,5: Test expression for if is assignment expression: i = foo() The condition test is an assignment expression. Probably, you mean to use == instead of =. If an assignment is intended, add an extra parentheses nesting (e.g., if ((a = b)) ...) to suppress this message. (-predassign will suppress message) xxx.c:13,5: Test expression for if not bool, type int: i = foo() Test expression type is not boolean or int. (-predboolint will suppress message)
Lint is telling you that you've probably made a mistake, in that you probably intended to do a comparison. The note about extra parentheses has nothing to do with "extra sequence points", but as a way of telling *lint* that you don't want it to complain about this. You can add 1, 5 or 500 parentheses and it won't change the result of the expression.
If you wish to call it bad practice, that's fine. But don't call it a compiler bug, because it's not.
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/
| |