01-10-2021, 09:31 AM
(This post was last modified: 01-10-2021, 09:33 AM by hummelvario.)
Hi,
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?
Example:
In this case the expression ((val) < 0.0) is invariant, but it is only once used initialising a constant (RMS_TO_AVERAGE).
Regards, Kevin
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?
Example:
Code:
#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