What is the performance implication of converting to bool in C++?

I was puzzled by this behaviour, until I found this link:

http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=99633

Apparently, coming from the Microsoft Developer who “owns” this warning:

This warning is surprisingly
helpful, and found a bug in my code
just yesterday. I think Martin is
taking “performance warning” out of
context.

It’s not about the generated code,
it’s about whether or not the
programmer has signalled an intent to
change a value from int to bool
.
There is a penalty for that, and the
user has the choice to use “int”
instead of “bool” consistently (or
more likely vice versa) to avoid the
“boolifying” codegen. […]

It is an old warning, and may have
outlived its purpose, but it’s
behaving as designed here.

So it seems to me the warning is more about style and avoiding some mistakes than anything else.

Hope this will answer your question…

:-p

Leave a Comment