Warning C4800..... why!
Hello newsgoups!
Please consider the following code:
c:\_DTS_PROGRAMMING\vc++\MY_APPS_LAB\XPPLC\WndProc.cpp(525) : warning C4800:
'LRESULT' : forcing value to bool 'true' or 'false' (performance warning)
This is a function called from the WM_COMMAND handler!
=========================================
void UpdatingSimInputs(LPARAM lParam,IO *io)
{
int ChildID;
//Get Child ID from Child window handle
ChildID = GetDlgCtrlID((HWND)lParam);
//Toggle checkbox value
SendMessage((HWND) lParam,BM_SETCHECK,(WPARAM)
!SendMessage((HWND)lParam,BM_GETCHECK,0,0),0);
switch(ChildID)
{
case 3:
io->b_ExtIn[0] = SendMessage((HWND)lParam,BM_GETCHECK,0,0); //Warning here
break;
case 4:
io->b_ExtIn[1] = SendMessage((HWND)lParam,BM_GETCHECK,0,0);//Warning here
break;
case 5:
io->b_ExtIn[2] = SendMessage((HWND)lParam,BM_GETCHECK,0,0);//Warning here
break;
case 6:
io->b_ExtIn[3] = SendMessage((HWND)lParam,BM_GETCHECK,0,0);//Warning here
break;
default:
break;
}
}
====================================================
At build time I get the following warning at four lines as indiceted above:
c:\_DTS_PROGRAMMING\vc++\MY_APPS_LAB\XPPLC\WndProc.cpp(525) : warning C4800:
'LRESULT' : forcing value to bool 'true' or 'false' (performance warning)
b_ExtIn is declared as a bool array as so:
bool b_ExtIn[3];
As per "help" it defines the warning as so:
"This warning is generated when a value that is not bool is assigned or
coerced into type bool. Typically, this message is caused by assigning int
variables to bool variables where the int variable contains only values true
and false, and could be redeclared as type bool. If you cannot rewrite the
expression to use type bool, then you can add "!=0" to the expression, which
gives the expression type bool. Casting the expression to type bool will not
disable the warning, which is by design."
I guess that SendMessage returns a LRESULT and not a bool! right... or not!
So at this point can I do what the help says, ..... add "!=0" to my
expression.
How do I do this..... like this:
io->b_ExtIn[0] = !=0 SendMessage((HWND)lParam,BM_GETCHECK,0,0);
Confused! I am looking for some kine of sample on how to merge the "!=0" to
my experssion!
Can someone help!
Thanks
--
Best regards
Robert