Rule 2.5 vs. include guards

Moderators: misra-c, david ward

Post Reply
sg2
Posts: 1
Joined: Thu Feb 09, 2017 11:55 am
Company: Altium

Rule 2.5 vs. include guards

Post by sg2 » Mon Feb 27, 2017 11:54 am

Hi.
It is not completely clear what is meant by use of a macro in Rule 2.5. There is definition of a use of an expression in the Glossary, but not of a macro.
If taken literally, rule 2.5 means that standard include guards are forbidden:

#ifndef HEADER_H
#define HEADER_H // Not used unless another #ifndef is encountered somewhere inside
...
#endif

misra-c
Posts: 548
Joined: Thu Jan 05, 2006 1:11 pm

Re: Rule 2.5 vs. include guards

Post by misra-c » Thu Mar 30, 2017 9:01 am

Your example is compliant with rule 2.5. The #ifndef HEADER_H is considered to be a use of the macro name, even though it appears before the #define.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “8.2 Unused code”