开发者

Refactoring MFC, do you use BOOL or bool [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

When should BOOL and bool be used in C++?

I'm currently tidying up a large C++ code base, which is primarily MFC and has a lot of BOOL variables and parameters. It also has a number of bools in there, which when compared yield a compiler warning;

warning C4800: 'BOOL' : forcing value to bool 'true' or 'false' (performance warning)

The plan is move to a clean compile with no warnings, at warning level 4 in VS2008. My choices are as follows;

  • Change all bools to BOOLs Change all
  • BOOLs to bools
  • Have the compiler not report warning 4800

What would you do, and more importantly why? I'm currently leaning towards the first option, as given the code contains a lot of MFC, there are a number of framework functions returning BOOL.

Edit Oops, prev开发者_StackOverflowiously asked question gives me the info I want. Closing...


Changing bool to BOOL globally might not help you. You probably have functions returning bool, or accepting bool. You will probably change one problem with another one. BOOL to bool can't be changed, too, because MFC (and Win32 API) use BOOL.

I would treat each warning generated in my code separately. Changing BOOL to bool can be done simple, compiler independent:

BOOL myBOOL; bool mybool;
mybool = (myBOOL != 0);

The other way around, it could be through an explicit cast (e.g. static cast), which should remove the warning.

This aproach has also the advantage that forces you to review all the BOOL to/from bool conversion points and you might find other issues (or not :) ).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜