MISRA Discussion Forums
14.3 and enum constants in macro expansion - Printable Version

+- MISRA Discussion Forums (https://forum.misra.org.uk)
+-- Forum: MISRA C (https://forum.misra.org.uk/forumdisplay.php?fid=4)
+--- Forum: MISRA C:2012 and MISRA C:2023 guidelines (https://forum.misra.org.uk/forumdisplay.php?fid=21)
+---- Forum: 8.14 Control statement expressions (https://forum.misra.org.uk/forumdisplay.php?fid=169)
+---- Thread: 14.3 and enum constants in macro expansion (/showthread.php?tid=1660)



14.3 and enum constants in macro expansion - Timofei - 19-10-2023

Hi,

We have a configuration macro with a value being an enum constant. We use that macro in an if-statement, and it violates the rule 14.3.

Code:
enum my_enum {
    MY_ENUM
};

#define CONF_MACRO MY_ENUM

if (CONF_MACRO == MY_ENUM) {...}


Note that in the case of enum constants we cannot convert the if-statement to a preprocessor #if-statement since the values of enum constants are not known at the preprocessing step. How can we solve this issue?


RE: 14.3 and enum constants in macro expansion - misra-c - 24-03-2024

It is recognised that, sometimes, violations of Guidelines will happen...

In this instance, MISRA C have published a permit [Permit / MISRA / C:2012 / R-14.3.A.1] which provides assistance in deviating Rule 14.3 due to build configurations.

https://www.misra.org.uk/app/uploads/2021/06/MISRA-C-2012-Permits-First-Edition.pdf