[previous] MISRA-C:2004  Rule  8.3:  (Required) [next] For each function parameter the type given in the declaration and definition shall be identical, and the return types shall also be identical.
The types of the parameters and return values in the prototype and the definition must match. This requires identical types including typedef names and qualifiers, and not just identical base types.

Example Code:


/* PRQA S 2982,3203,3447,3408 ++ */

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

typedef int SPEC16;

static S16 test_0803c();                   /* MISRA Violation - Rule 16.5 */
static SPEC16 test_0803e(void);

static S16 test_0803c( px )                /* MISRA Violation  - Rule 8.1 */
const S16 *px;
{
   return *px;
}

extern S16 test_0803( void )
{
   S16 r;

   r = test_0803a( 1 );                    /* MISRA Violation - Rule 8.1 */
   r = test_0803a( 1, 2 );                 /* MISRA Violation */
   r = test_0803b( 1, 2 );                 /* MISRA Violation - also Rule 8.1 */
   r = test_0803c( 2 );                    /* MISRA Violation */
   r = test_0803d( 1, 2 );                 /* MISRA Violation - also Rule 8.1 */
   r = test_0803e( );

   return r;
}

extern S16 test_0803b( void );

extern S16 test_0803d( S16 x )
{
   return x + 1;
}

static S16 test_0803e(void)                /* MISRA Violation */
{
    return 1;
}


QAC messages that encompass this guideline:

0624 Function '%s' is declared using typedefs which are different to those in a previous declaration.
1331 Type or number of arguments doesn't match previous use of the function.
1332 Type or number of arguments doesn't match prototype found later.
1333 Type or number of arguments doesn't match function definition found later.
3320 Type of argument no. %s differs from its type in definition of function.
3675 Function parameter declared with type qualification which differs from 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