MISRA Discussion Forums
Rule 8.5 - #define with function code in header files - 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: 2004 rules (https://forum.misra.org.uk/forumdisplay.php?fid=17)
+---- Forum: 6.8 Declarations and Definitions (https://forum.misra.org.uk/forumdisplay.php?fid=35)
+---- Thread: Rule 8.5 - #define with function code in header files (/showthread.php?tid=1199)



Rule 8.5 - #define with function code in header files - reito - 18-08-2015

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.


Re: Rule 8.5 - #define with function code in header files - misra-c - 18-09-2015

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.