Re: bool or BOOL in MFC projects

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



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 message
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

Joseph M. Newcomer [MVP]
email: newcomer@xxxxxxxxxxxx
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
.



Relevant Pages

  • Re: Access violation with CFtpFileFind ::FindFile
    ... outward to the first recognizable code (such as in the MFC library) and report what it is. ... bWorking = finder.FindFile; ... extern BOOL Calculate_Average_CFile(CString LastFile); ...
    (microsoft.public.vc.mfc)
  • Re: C++ DLL Usage (p/invoke?)
    ... BOOL CreateCtrl(CWnd* pParentWnd, int top, int left, int bottom, int ... maybe you can recode it a little to take a HWND as its first argument. ... I know enough MFC to believe that this is possible, ... Interop.Marshal to convert an mfc BOOL into a VB Boolean. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: bool or BOOL in MFC projects
    ... The problem is that the API is written in C, which does not support overloading; ... mean a duplication of the MFC API in C++ over the current duplication. ... BOOL versions of the functions pretty easily. ...
    (microsoft.public.vc.mfc)
  • Re: bool or BOOL in MFC projects
    ... bool or BOOL in MFC projects ... with MFC you are never far away from the raw intricacies ...
    (microsoft.public.vc.mfc)
  • Re: Probleme bei Migration von MFC auf Active X
    ... > Wie hast du dein ATL Projekt erstellt? ... um die MFC zu initialisieren. ... BOOL CFxlsApp::InitInstance ... In der FwObjDll ist die Cut and Paste Funktionalität drin. ...
    (microsoft.public.de.vc)