I've been working with some code to ensure MISRA compliance. The issue with this piece of code is
Operands shall not be of an inappropriate essential type. The operand of the ? operator is of an inappropriate essential type category unsigned.
I assume the issue is with the first argument being an unsigned data type, instead of boolean, which means the fix bellow would work.
The original,
return (uint32Var & 0x80000000u) ? 0u : 1u;
My change to the code,
return ( (uint32Var & 0x80000000u)!=0u ) ? 0u : 1u;
Is this a correct change to make? I'm concerned about changing the functionality of the code but as far as I know, at least in if logic, the operand is evaluated as numVar != 0
inside the if ( numVar )
operator.