|
-
April 11th, 1999, 07:24 AM
#1
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!
-
April 11th, 1999, 01:42 PM
#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.
-
April 12th, 1999, 12:30 AM
#3
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.
-
April 12th, 1999, 04:40 AM
#4
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|