I’m not sure I like this being valid. In my universe a bool is a bool is a bool is a bit.
unsigned char a, b, c, d ;
typedef unsigned UINT32 ;
UINT32 x ;
x = (a < < 24) | (b << 16) | (c < 8) | (d) ;[/sourcecode] "x is a shifted left 24 bits plus b shifted left 16 bits plus (is c less than 8?) plus d" Why can I shift an unsigned char 24 bits left? (Intel's compiler secretly casts to a signed int, regardless of the signedness of your input variable, GCC appears to be a bit smarter, Visual C seemed to be rather smart). Ok, I can, but why am I allowed to bitwise OR a bool? Nothing on any of the 3 compilers we use will elicit a peep out of a compiler. (c < 8) evaluates to a bool. It seems like it would make sense to restrict bools to logical OR. [sourcecode language='c++']bool a = true, b = false ; bool c = (a || b) ;[/sourcecode]
Recent Comments