That's not exactly what happened. You mentioned a crash and gave no code and no context. I'm not really sure what you expected.
Printable View
parentheses are free!
Wouldn't if((a==b) && (b==c)) work for a true outcome?
ElectricCash, you see, the reason I started this thread is because it was somewhat confusing to me when I came across that double equation comparison statement. I have an experience of well over 15 years with C/C++ and I was thrown off by it, I should admit. What made it confusing for me is a mathematical notation (that involves the use of the AND operator in its logic) which is not the case for the way that statement is evaluated in C. Again, I'm not arguing with C/C++ standards -- we cannot change them from here -- but in my book a compiler should issue a warning when such statement is encountered, since clearly, if a, b and c are all int's comparing a boolean (which is the result of the first comparison) to an int, although possible, makes little sense. Again, this is my opinion and I learned my lesson.
Hmmm, yeah. I would have expected something like this:
However, this warning only trips on this 'if' stmt:Code:1>d:\projects\junkconsole\test.cpp(15) : warning C4805: '==' : unsafe mix of type 'bool' and type 'int' in operation
ViggyCode:bool res = a == b;
if(res == c)
{
d++;
}
I suspect that for legacy C compatibility reasons, primitive comparisons actually return int rather than bool.