17-12-2020, 08:29 AM
The MISRA checker I am using is rejecting operators in #if as noted in the following code.
According to the supplier, the constant '1' (or '0' when used in the same way) is being interpreted as a signed int and therefore the operators '!', '&&' and '||' cannot be used with it.
Is the checker's interpretation correct?
Code:
#define TRUE 1
#define Condition1 TRUE
#define Condition2 TRUE
#if Condition1 /* Accepted */
#endif
#if !Condition1 /* Rejected */
/* Rejection is because:
Unpermitted operand to operator '!' [MISRA 2012 Rule 10.1, required]
*/
#endif
#if Condition1 && Condition2 /* Rejected */
/* Rejection is because:
Unpermitted operand to operator '&&' [MISRA 2012 Rule 10.1, required]
*/
#endif
#if Condition1 || Condition2 /* Rejected */
/* Rejection is because:
Unpermitted operand to operator '||' [MISRA 2012 Rule 10.1, required]
*/
#endif
Is the checker's interpretation correct?