#: 12056 S3/Languages
03-Sep-91 01:13:54
Sb: #12054-#C fun
Fm: James Jones 76257,562
To: Bob van der Poel 76510,2203 (X)
This is one of many places in which C's sloppy type system trips one up. The
relational operators have a result of type int, and, oddly enough for a
descendant of BCPL, relationals don't elide in the way you were hoping for
(BCPL itself would have done what you wanted, I believe). So...
if (a == b == 3)
compares a with b, and then compares 1 with 3 if they are equal, 0 with 3 if
they are not. Since neither 1 nor 0 are equal to 3, the condition will never
be true, and the then clause of the if will never be reached.
There are 2 Replies.
|