Lars Gullik Bjønnes wrote:
> | Obviously, I'm in a pedantic mood. These two are casts:
> | (bool)1;
> | static_cast<bool>(1);
> | This one isn't:
> | bool(1);
>
> I think I still prefere this last one.
When we compile with a C++ compiler then it casts with
a static_cast<bool> a int to bool, therefore the warning.
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).
I'm not sure if the bool constructor -bool::bool(int)-
is really as fast as the casts.
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.
Peter