MISRA Discussion Forums

Full Version: Rule 14.3 and preprocessor constants
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

I have a question regarding a reported MISRA violation in our code, which isn't completely clear to me after reading the MISRA Guidelines.

Does the MISRA C:2012 Rule 14.3 (Controlling expressions shall not be invariant) also apply to predefined constants, which include function-lika macros?


#define ROUND_TO(type, val) ((type) (((val) < 0.0) ? ((val) - 0.5) : ((val) + 0.5)))

#define RMS_TO_AVERAGEĀ  ROUND_TO(uint16_t, ((70.0) / (1.11)))

In this case the expression ((val) < 0.0) is invariant, but it is only once used initialising a constant (RMS_TO_AVERAGE).

Regards, Kevin
As the rules stand, your example violates both rules 14.3 and 2.2.

The rules covering invariant controlling expressions (rule 14.3) and subsequent dead code (rule 2.2) in macro definitions are currently being reviewed by the MISRA C Working Group.