On Jul 24, 2009, at 12:48 AM, Sebastian Redl wrote: > Ted Kremenek wrote: >> On Jul 23, 2009, at 9:33 PM, Eli Friedman wrote: >> >>> (int)x == false is semantically equivalent to (int)x == 0 due to >>> integer promotion rules. That said, it is slightly confusing the >>> way >>> it's written. >>> >> >> >> The problem isn't with 'x == 0', but with 'x == -1'. Since (I >> believe) both '1' and '-1' convert to true when int is casted to a >> bool, the 'KnownVal == true' would evaluate to true in both cases >> (which isn't the desired behavior). >> > Integer promotion rules are the same no matter the values. In KnownVal > == true the 'true' literal is converted to the integer 1, and KnownVal > is not touched.
Ah that's right. The promotion is from bool to int, not the other way around. Thanks Eli and Sebastian. I think what my concern was with this code is that someone (mistakenly) could write 'KnownVal' instead of 'KnownVal == true' or '!KnownVal' instead of 'KnownVal == false' and not realize that they were fundamentally changing the logic of the code. _______________________________________________ cfe-commits mailing list [email protected] http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
