4 ms·
bool a = value & (1 << 5) a will be 1 or 0, not 1 << 5. You don't get this behavior with a normal int. MSVC also has a warning about some of this behavior [1],
by revelation 13y ago
bool a = value & (1 << 5)
a will be 1 or 0, not 1 << 5. You don't get this behavior with a normal int.
MSVC also has a warning about some of this behavior [1], with a nonsense performance subtext. I don't think theres a GCC equivalent.
1: http://msdn.microsoft.com/en-us/library/b6801kcy.aspx http://msdn.microsoft.com/en-us/library/b6801kcy.aspx
- deleted 13y ago[deleted]
- skybrian 13y agoSeems like the only reason you'd expect it to be 1 << 5 is that you've been working with a broken definition of bool using #define. In any sane language you can't redefine bool that way, nobody would ever expect bool to take more than two values, and there wouldn't be a problem.
- kansface 13y agoBut, this is the case in every other language I can think of. IE, bools have one of two possible states; as a human 1<<5 is neither true nor false.