Rule 2.5 unsued macro definition

Moderators: misra-c, david ward

Post Reply
Posts: 2
Joined: Thu Jun 01, 2017 12:47 pm
Company: ...

Rule 2.5 unsued macro definition

Post by sowiso » Fri Sep 08, 2017 9:55 am


I have the following code:

Code: Select all

/* uncomment next line if the feature is needed for your project */
/* #define activate_feature */

#ifdef activate_feature

#ifdef protected_feature
/* limited visibility stuff */
#endif /* protected feature */

#endif /* activate feature */


#define protected_feature

#include "cfg.h"
#include "feature.h"

#ifdef activate_feature
#endif /* activate feature */

The code is part of a library which is used in various projects which shall be MISRA2012 compliant.
Based on each project a different version of cfg.h is used which configures the project specific needs.
In projects where activate_feature is not defined I always got a claim from my code checking tool that the macro protected_feature is not used.
Is this really a violation of Rule 2.5 or is the code checker wrong?
If it is a violation how to handle code where parts a selected by conditional compiling?

Posts: 571
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 2.5 unsued macro definition

Post by misra-c » Thu Sep 21, 2017 1:01 pm

The rationale for rule 2.5 is that it is unclear to a reviewer whether an unused macro is intentionally redundant or whether it was left unused by mistake. The example is not compliant with rule 2.5.
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.2 Unused code”