Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

MISRA.FUNC.NOPROT.DEF.2012

MISRA C 2012 Rule 8.4: A compatible declaration shall be visible when an object or function with external linkage is defined

Function has a definition but no prototype.

C90 [Undefined 24], C99 [Undefined 39]

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

A compatible declaration is one which declares a compatible type for the object or function being defined.

Rationale

If a declaration for an object or function is visible when that object or function is defined, a compiler must check that the declaration and definition are compatible. In the presence of function prototypes, as required by Rule 8.2, checking extends to the number and type of function parameters.

The recommended method of implementing declarations of objects and functions with external linkage is to declare them in a header file, and then include the header file in all those code files that need them, including the one that defines them (See Rule 8.5).

Example

In these examples there are no declarations or definitions of objects or functions other than those present in the code.

extern int16_t count;
       int16_t count = 0;            /* Compliant                     */

extern uint16_t speed = 6000u;       /* Non-compliant - no declaration
                                      * prior to this definition      */ 
uint8_t pressure = 101u;             /* Non-compliant - no declaration
                                      * prior to this definition      */

extern void func1 ( void ); 
extern void func2 ( int16_t x, int16_t y ); 
extern void func3 ( int16_t x, int16_t y );

void func1 ( void ) 
{
  /* Compliant */ 
}

The following non-compliant definition of func3 also violates Rule 8.3.

void func2 ( int16_t x, int16_t y ) 
{
  /* Compliant                                 */ 
}

void func3 ( int16_t x, uint16_t y ) 
{
  /* Non-compliant - parameter types different */ 
}

void func4 ( void ) 
{ 
  /* Non-compliant - no declaration of func4 before this definition      */ 
}

static void func5 ( void ) 
{
  /* Compliant - rule does not apply to objects/functions with internal
   * linkage                                                             */ 
}

See also

Rule 8.2, Rule 8.3, Rule 8.5, Rule 17.3