MISRA 8.5 with inline function - 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: MISRA 8.5 with inline function (/showthread.php?tid=1056) |
MISRA 8.5 with inline function - ziomocci - 15-05-2014 Hi guys, I have an header file with inline function, like: Code: inline void DIGIO_InOut(uint8_T type, uint16_T pid) Well, activating the rules, of course I can not keep body of inline function inside header file (just for info, I am using ghs compiler). Is it possible to put declaration of inline function in and declaration in , like: Code: inline void DIGIO_InOut(uint8_T type, uint16_T pid); Thank you in advance, Best regards, Andrea Mocci, Embedded SW developer at Akhela s.r.l. Re: MISRA 8.5 with inline function - ziomocci - 15-05-2014 Resolved following C99 standard: declared in my_file.h Code: extern void my_func(void); and defined in my_file.c Code: inline void my_func(void) my_func is callable from other modules and code is MISRA 8.5 fully compliant. Regards Andrea Mocci, embedded SW developer @ Akhela s.r.l. Re: MISRA 8.5 with inline function - misra-c - 06-06-2014 The use of "inline" results in a violation because it does not form part of C90 (which MISRA-C:2004 is based on) but was introduced for C99. It is recognised that many compilers support the use of the inline keyword, and the MISRA-C Committee will be issuing further guidance in the near future. The use of "inline" breaks MISRA-C:2004 rule 1.1, which states Quote: All code shall conform toIf your compiler supports "inline", you will need to deviate MISRA rule 1.1. MISRA rule 8.5 does not consider "inline" as it is not part of the C90 language. Tools may therefore vary as to whether they give a message if "inline" is present in a header file. A deviation for "inline" might include such information as 1. All inline function definitions shall be identified. 2. The performance advantage gained by use of an inline function shall be quantified. An inline function shall not be used unless it is necessary in order to meet performance requirements. 3. An inline function shall be declared with the static storage class specifier. 4. If an inline function is to be used in more than one translation unit it shall be located within a header file. 5. An inline function shall not be defined in a header file unless it is used in more than one translation unit MISRA C:2012 permits the use of inline functions in header files, but requires that they are declared with static storage class, as otherwise the behaviour is undefined if the function is not defined in the same translation unit. In that situation, a call to an inline function declared with external linkage may either call the external definition of the function or it may use the inline definition. Although this should not affect the behaviour of the called function, it might affect execution timing and there have an impact on a real-time program. |