Rule 8.5 - #define with function code in header files

6.8 Declarations and Definitions

Moderators: misra-c, david ward

Post Reply
reito
Posts: 2
Joined: Wed Dec 03, 2014 7:06 am
Company: GMV

Rule 8.5 - #define with function code in header files

Post by reito » Tue Aug 18, 2015 3:47 pm

Hello,
I would like to confirm the following interpretation of the rule 8.5. The rule says that "Header files should be used to declare objects, functions, typedefs, and macros. Header files shall not contain or produce definitions of objects or functions (or fragment of functions or objects) that occupy storage."

I have seen a couple of alerts in code raised when the header file contains a macro that generates the "body of one function". My understanding is that this is the case where the "macro produces definitions of objects or functions", and that this is a violation to be corrected.

In a similar way, if the header file contains a #typedef for an struct, should it be considered a violation to this rule?

Thanks in advance.

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

Re: Rule 8.5 - #define with function code in header files

Post by misra-c » Fri Sep 18, 2015 1:09 pm

Header files which contain the typedef for a struct do not violate rule 8.5.

We are unclear what is meant to be "a macro that generates the body of one function", and so can not comment on that part of the question without an example.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.8 Declarations and Definitions”