CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    May 1999
    Posts
    388

    m_bChech == true results in warning!

    I am using the if expression with boolean data types. The strang thing is that comparison with false does not give error but the same with true gives error.

    if (m_bCheck == false); // ok
    if (m_bCheck !=true); // ok
    if (m_bCheck == true); // Here it gives warning message related to == operator.
    // says one side is const bool and other is somthing else...

    Please help with this!


  2. #2

    Re: m_bChech == true results in warning!

    I bet m_bCheck is declared as BOOL instead of bool. BOOL is an int. bool is a bool. Don't mix the two.

    Next time, post the warning message, like "warning C4805: '==' : unsafe mix of type 'int' and type 'const bool' in operation".)


    LA Leonard - Definitive Solutions, Inc.

  3. #3
    Join Date
    May 1999
    Posts
    388

    warning C4805: '==' : unsafe mix of type 'int' and type 'const bool' in operation

    Thankx for pointing out the error so precisely.
    I understand both BOOL & bool, takes the values false and true, so is the difference only in return type?

    "BOOL Boolean variable (should be TRUE or FALSE" // from vc help

    Is there any kind of difference between true & TRUE, and similarly between false & FALSE.


  4. #4
    Join Date
    Apr 1999
    Posts
    383

    Re: warning C4805: '==' : unsafe mix of type 'int' and type 'const bool' in operation

    As LA Leonard said, BOOL and bool are different types. TRUE and FALSE are #defines for int values (generally 1 and 0 respectively). true and false are the two permitted values of type bool.

    bool has conversions to int, but if you want to convert a BOOL to a bool (e.g. a BOOL return value from a Win32 API), you can do something clunky like:

    bool ret = BOOL_Func() != FALSE;

    or even:

    bool ret = !!BOOL_Func();

    Wrap the conversion in a utility function, and you can select how you do it without upsetting things:

    bool to_bool(BOOL b) { return FALSE != b; }
    bool ret = to_bool(BOOL_Func());

    Dave



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured