I read all these answers about why true is true and why two boolean variables can be compared using == or != , Except in rare cases when an integer is forcibly used like bool or some such thing. However, I have the same problem like the original poster. I have two logical variables, each of which is โtrueโ, but when I compare them, I think that they are not equal. Here is a line of code,
if (angDegDiff > 15 || scaleRatioA > 5 || scaleRatioB < -5 || (isParallel2 != isParallel1)) { return false; }
In my example, angDegDiff = 0 , scaleRatioA = 0 , scaleRatioB = 0 , isParallel2 = true and isParallel1 = true . However, the expression evaluates to true , and the only way to do this is if isParallel2 not equal to isParallel1 .
No fancy methods are used to set the values โโof isParallel1 or isParallel2 . Their values โโare set using an expression of type _isParallel = true; . Later this value is copied to another variable using an instruction like isParallel1 = geom1->IsParallel(); which is implemented as return _isParallel; .
My conclusion is that, depending on the compiler, two boolean variables cannot be reliably mapped for equality. I am using Microsoft Visual C ++ 2005, Version 8.0.50727.4039.
Epilogue: I replaced the logical comparison in my code with the expression ((isParallel1 && !isParallel2) || (!isParallel1 && isParallel2)) , and now everything works fine.
source share