Lars Gullik Bjønnes wrote: > Peter Kümmel <[EMAIL PROTECTED]> writes: > > | When we use a C compiler then it uses the C-style cast (bool), > | so I think the correctest way is to use static_cast<bool>, > | but this is so ugly that I would prefer (bool). > > C-style casts are just too powerful... don't use them.
I agree. > | I'm not sure if the bool constructor -bool::bool(int)- > | is really as fast as the casts. > > I am. If you are not, please provide measurements. When you are sure, I also would prefer bool(). > | But sometime it would simple help to "code what you mean" :) > | > | Here an example: > | > | enum type{...} > | bool match(type a, type b) { return (a & b); } > | > | Does this not mean a==b? So why not write it down? > | So we will get a boolean without any casts. > > That depends.... it could very well mean ((a & b) == b) Yes, I forgot 11 & 10 = 10 > 0 = true. > (and also if (a & b) is not b, then (a & b) is 0, so the explict > comparison should not be needed.) Does the compiler not always generates a comparison with 0? (Maybe because of this the warning) > If a is a bit-field the (a & b) is a pretty usual construct. > (bit-field in the 1,2,4,8,16 sense)