MISRA Discussion Forums

Full Version: 14.3 and enum constants in macro expansion
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
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?
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/202...dition.pdf