I have a simple macro function which will check the condition and return an Boolean value. Below is the snippet of code
assume: #define boolean bool
Test.h file
#define CHECK_STATE(X) (boolean)(STATE_VALUE == (uint8)(X) )
Test.c file
enum MY_STATE{
STATE_0,
STATE_1,
STATE_2
};
static uint8 STATE_VALUE = (uint8)STATE_0; //This value update in the code dynamically from state 0 to 2
if(CHECK_STATE(STATE_1)) /*MISRA warning: Controlling expression is not an 'essentially Boolean' expression. */
{
/*If condition pass*/
}
else
{
/*If condition failes*/
}
In the above code CHECK_STATE
function will return a Boolean value. So if loop can check either true or false. So why MISRA is throwing the warning "not an 'essentially Boolean' expression" ? Any suggestion to fix this type of warnings?