[previous] MISRA-C:2004  Rule  8.1:  (Required) [next] Functions shall have prototype declarations and the prototype shall be visible at both the function definition and call.
The use of prototypes enables the compiler to check the integrity of function definitions and calls. Without prototypes the compiler is not obliged to pick up certain errors in function calls (e.g. different number of arguments from the function body, mismatch in types of arguments between call and definition). Function interfaces have been shown to be a cause of considerable problems, and therefore this rule is considered very important.

The recommended method of implementing function prototypes for external functions is to declare the function (i.e. give the function prototype) in a header file, and then include the header file in all those code files that need the prototype (see Rule ).

The provision of a prototype for a function with internal linkage is a good programming practice.

Example Code:


/* PRQA S 3210 ++ */

#include "misra.h"
#include "m2cmex.h"

static S16 test_0801a( a )         /* MISRA Violation Rule 8.1 */
S16 a;
{
   return a;
}

extern S16 test_0801( void )
{
   S16 r;
   r = test_0801a( 1 );

   r = r + test_0801b( );          /* MISRA Violation Rule 8.1 */
   return r;
}


QAC messages that encompass this guideline:

3002 Defining '%s()' with an identifier list and separate parameter declarations is an obsolescent feature.
3335 No function declaration. Implicit declaration inserted: 'extern int %s();'.
3450 Function '%s', with internal linkage, is being defined without a previous declaration.



(c) The Motor Industry Research Association, 2004
QA C Source Code Analyser 8.1.2
MISRA-C:2004 Compliance Module 3.2
© 2013 Programming Research
www.programmingresearch.com
Personality Groups | Glossary | Message Index | MISRA-C:2004 Rule Index Contents