11-12-2015, 01:08 PM
MISRA C:2012 requires both function declarations and definitions with internal linkage to be in prototype form (rule 8.2).
However MISRA C:2012 does not require there to be a separate declaration in addition to the definition for functions with internal linkage. For example:
It should be noted that the MISRA C:2012 guidelines use the term "prototype" as defined in the C standard. The term refers to the declaration of a function that declares the types of its parameters (C99 6.2.1(2)) and applies equally to (non-defining) declarations and to definitions.
In summary:
However MISRA C:2012 does not require there to be a separate declaration in addition to the definition for functions with internal linkage. For example:
Code:
static void fn ( int32_t i32 ); /* Declaration required by MISRA-C:2004 rule 8.1,
but not in MISRA C:2012.
If the declaration is present, then it must
be in prototype form.
*/
static void fn ( int32_t i32 ) /* Definition required to be in prototype form by
MISRA-C:2004 rule 8.1 and MISRA C:2012 rule 8.2
*/
{
....
}
In summary:
- The interface to a function must always be declared in prototype form. (MISRA C:2004 Rule 8.1, MISRA C:2012 Rule 8.2)
- The interface to a function must never be defined "implicitly", i.e. by calling the function in the absence of a previous declaration or definition. (MISRA C:2004 Rule 8.1, MISRA C:2012 Rule 17.3)
- For a function has external linkage, the interface to that function must be declared consistently across all translation units. (MISRA C:2004 Rules 8.1 & 8.8, MISRA C:2012 Rules 8.4 & 8.5)
- For a function with internal linkage,
- MISRA C:2004 Rule 8.1 requires a (non-defining) declaration in advance of the function definition or any call to the function.
- MISRA C:2012 does not require a (non-defining) declaration in advance of the function definition.
- MISRA C:2012 Rule 17.3 requires either a (non-defining) declaration or the function definition in advance of any call to the function.
- MISRA C:2004 Rule 8.1 requires a (non-defining) declaration in advance of the function definition or any call to the function.
Posted by and on behalf of the MISRA C Working Group