MISRA Discussion Forums
Rule 14.3 and preprocessor constants - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forum-4.html)
+--- Forum: MISRA C:2012 guidelines (https://forum.misra.org.uk/forum-21.html)
+---- Forum: 8.14 Control statement expressions (https://forum.misra.org.uk/forum-169.html)
+---- Thread: Rule 14.3 and preprocessor constants (/thread-1581.html)



Rule 14.3 and preprocessor constants - hummelvario - 01-10-2021

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:

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


RE: Rule 14.3 and preprocessor constants - misra-c - 27-11-2021

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.