MISRA 8.5 with inline function

6.8 Declarations and Definitions

Moderators: misra-c, david ward

Post Reply
ziomocci
Posts: 4
Joined: Tue Jan 14, 2014 4:18 pm
Company: akhela

MISRA 8.5 with inline function

Post by ziomocci » Thu May 15, 2014 2:51 pm

Hi guys,

I have an header file with inline function, like:

Code: Select all

<my_file.h>
inline void DIGIO_InOut(uint8_T type, uint16_T pid)
{
    /* Do something */
}
and, without MISRA 8.5 activated, I am able to use/export methods without problems.

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 <my_file.h> and declaration in <my_file.c>, like:

Code: Select all

<my_file.h>
inline void DIGIO_InOut(uint8_T type, uint16_T pid);

<my_file.c>
inline void DIGIO_InOut(uint8_T type, uint16_T pid)
{
    /* Do something */
}
?

Thank you in advance,

Best regards,

Andrea Mocci, Embedded SW developer at Akhela s.r.l.

ziomocci
Posts: 4
Joined: Tue Jan 14, 2014 4:18 pm
Company: akhela

Re: MISRA 8.5 with inline function

Post by ziomocci » Thu May 15, 2014 7:13 pm

Resolved following C99 standard:

declared in my_file.h

Code: Select all

extern void my_func(void); 
and defined in my_file.c

Code: Select all

inline void my_func(void)
{
    /* DO SOMETHING */ 
}
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.

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

Re: MISRA 8.5 with inline function

Post by misra-c » Fri Jun 06, 2014 8:24 am

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
All code shall conform to
ISO/IEC 9899:1990 C "Programming languages - C", amended and corrected by
ISO/IEC 9899/COR1:1995,
ISO/IEC 9899/AMD1:1995, and
ISO/IEC 9899/COR2: 1996
If 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.
---
Posted by and on behalf of
the MISRA C Working Group

Post Reply

Return to “6.8 Declarations and Definitions”