Messages in this thread | | | From | (Chris Adams) | Subject | Re: fork() Problem? | Date | 6 May 1999 00:20:06 -0500 |
| |
Once upon a time, Richard B. Johnson <root@chaos.analogic.com> said: >On Wed, 5 May 1999, Manuel A. McLure wrote: >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.
Wrong. If what you say happens, then the compiler is broken. The value of an assignment expression is the value of the left hand part AFTER the assingment. So,
if(a=b)
is EXACTLY the same as
a=b; if(a)
>This, as I explained over and over again, is called a >"boolean test of assignment error". It is a real error because, >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.
If your compiler always evaluates the assignment in "if(a=b)" to true, then your compiler is broken according the C standard. That and/or your lint is broken WRT the C standard.
You keep talking about boolean in C. There is no such thing in the language. In C, the result of the expression (which must be of pointer or arithmatic type) in the if is compared to 0.
>Regardless of the flames or comments I will have nothing further >to say about this.
Ahh, the good old "quit while your behind" method. Don't go away mad, Dick, just go away. -- Chris Adams <cadams@ro.com> - System Administrator Renaissance Internet Services - IBS Interactive, Inc. Home: http://ro.com/~cadams - Public key: http://ro.com/~cadams/pubkey.txt I don't speak for anybody but myself - that's enough trouble.
- 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/
| |