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.OBJ.TYPE.COMPAT

Type not compatible with type of other declaration.

MISRA-C Rule 8.4 (required): If objects or functions are declared more than once their types shall be compatible.

[Undefined 10]

The definition of compatible types is lengthy and complex (ISO/IEC 9899:1990 [2], sections 6.1.2.6, 6.5.2, 6.5.3 and 6.5.4 give full details). Two identical types are compatible but two compatible types need not be identical. For example, the following pairs of types are compatible:

Example

signed int            int
char [5]              char []
unsigned short int    unsigned short

MISRA-C++ Rule 3-2-1 (required): All declarations of an object or function shall have compatible types.

[NDR 3.2(3), Undefined 3.2(5)]

Rationale

It is undefined behaviour if the declarations of an object or function in two different translation units do not have compatible types.

The easiest way of ensuring object or function types are compatible is to make the declarations identical.

Example

// File a.cpp
extern int32_t a;
extern int32_t b [];
extern char_t c;

int32_t f1 ( );
int32_t f2 ( int32_t );

// File b.cpp
extern int64_t a;          // Non-compliant — not compatible
extern int32_t b [ 5 ];    // Compliant
int16_t c;                 // Non-compliant

char_t f1 ( );             // Non-compliant
char_t f2 ( char_t );      // Compliant — not the same function as
                           //             int32_t f2 ( int32_t )