Since != and == have the same precedence, we have to fall back to their associativity. In this case, it's right to left. So if we parenthesized your original statement it would be:
Code:
if ( 'R' == (name[0] != 'R') )
So first,
would be evaluated. This would evaluate to 0 or 1 (sorry, I don't have the standard in front of me. I know for false it would be 0, and believe very strongly that true will evaluate to 1).
So next, either:
or
would be evaluated. This is where it gets tricky. The compiler will have to make an implicit cast as a char literal and the result of a boolean operator are not the same type. If 0 or 1 are cast to a char, then you are comparing:
or
This will always be false. However, if 'R' was cast to a "logical" (this isn't a type, but the compiler might be filling in some gaps for you) it is non-zero, so it would evaluate to true/logical 1. So then you would have:
or
So now this expression will evaluate to false/0 if name[0] != 'R' is false/0 or true/1 if name[0] != 'R' is true/1. In this situation, the statements would collapse to:
which is what you intended in the first place. Another option that I won't suss out completely is the compiler implicitly casting 'R' to an int, which would be 82. This compared to 0 or 1 would always be false just as if 0 or 1 were cast to a char.
Since I don't have the standard available I can't say which is "correct", but it may not be specified so this may be up to the interpretation of the compiler. The only time you would have gotten what you wanted was if, for logicals, the compiler tried to enforce != 0 strictly.
Such is the shortfall of a language without a boolean type.
Sorry this couldn't be more definitive, but hopefully it's at least somewhat enlightening in terms of the possibilities for the compiler's behavior. If you really want to see what gcc is doing, hand it a -S switch. I would try to isolate the offending code to make the resulting ASM easier to read.
-Lee