Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MISRA 8.5 with inline function
#1
Hi guys,

I have an header file with inline function, like:
Code:
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 and declaration in , like:
Code:
inline void DIGIO_InOut(uint8_T type, uint16_T pid);


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.
<t></t>
Reply
#2
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)
{
    /* 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.
<t></t>
Reply
#3
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 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
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)