Re: bool or BOOL in MFC projects
- From: Joseph M. Newcomer <newcomer@xxxxxxxxxxxx>
- Date: Tue, 18 Dec 2007 11:44:01 -0500
There are additional problems; for example, sizeof(BOOL) != sizeof(bool), so if Microsoft
suddenly changed
typedef int BOOL;
to
typedef bool BOOL;
everyone's code would break horribly. Every struct that used BOOL would change size, for
example. It would also require massive rework of the API, which would break nearly every
existing program in ways too horrible to imagine. Therefore, it is not going to change
because it cannot change.
I largely follow David's style; bool doesn't really buy all that much most of the time. I
find that the more I use STL, the more bools creep into my code, but they are limited to
STL-based code.
joe
On Tue, 18 Dec 2007 13:28:48 GMT, "David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote:
"Stuart Redmann" <DerTopper@xxxxxx> wrote in messageJoseph M. Newcomer [MVP]
news:fk884c$bl$1@xxxxxxxxxxxxxxx
It's a pitty that MFC didn't change the Win32 type BOOL to the C++ type
bool (after all, MFC is a C++ API). The overhead of the conversion between
BOOL and bool can be neglected by any application that deals with a
graphical user interface provided by GDI.
The thing is, with MFC you are never far away from the raw intricacies of
Windows. I think as long as the raw Windows API's use BOOL, it makes sense
for MFC to use BOOL also because MFC interacts with the raw API's so much.
If you're not careful, the differences of bool and BOOL can bite you,
especially with things like COM access.
My practice is to use BOOL throughout an MFC app. Old fashioned, perhaps.
But entirely consistent, and I never have to ask whether to use bool or BOOL
or be annoyed by the pesky warning about C++ performance when using a BOOL
when bool was expected or vice-versa. Since, as you say, the actual
performance gain of a bool in GUI apps is negligible. To me, why use 2
things when 1 suffices?
-- David
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.
- References:
- bool or BOOL in MFC projects
- From: Vaclav
- Re: bool or BOOL in MFC projects
- From: Stuart Redmann
- Re: bool or BOOL in MFC projects
- From: David Ching
- bool or BOOL in MFC projects
- Prev by Date: Re: debugging missing images in a CTreeCtrl
- Next by Date: Re: run-time speed
- Previous by thread: Re: bool or BOOL in MFC projects
- Next by thread: Re: bool or BOOL in MFC projects
- Index(es):
Relevant Pages
|