06-06-2014, 07: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
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.
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.
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
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