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.LINKAGE.EXTERN

Declaration with external linkage not in header file.

MISRA-C++ Rule 3-3-1 (required): Objects or functions with external linkage shall be declared in a header file.

Rationale

Placing the declarations of objects and functions with external linkage in a header file documents that they are intended to be accessible from other translation units.

If external linkage is not required, then the object or function shall either be declared in an unnamed namespace or declared static.

This will reduce the visibility of objects and functions, which is considered to be good practice.

Exception

This rule does not apply to main, or to members of unnamed namespaces.

Example

// header.hpp
extern int32_t a1;
extern void f3 ( );

// file1.cpp
#include "header.hpp"

      int32_t a1 = 0;   // Compliant
      int32_t a2 = 0;   // Non-compliant
static int32_t a3 = 0;  // Compliant

namespace
{
   int32_t a4 = 0;      // Compliant
   void f1 ()           // Compliant
   {
   }
}

static void f2 ( )      // Compliant
{
}

void f3 ( )             // Compliant
{
   a1 = 1;
   a2 = 1;
   a3 = 1;
   a4 = 1;
}
void f4 ( )             // Non-compliant

{
   a1 = 2;
   a2 = 2;
   a3 = 2;
   a4 = 2;
}

void main ( )           // Compliant by exception
{
   f1 ( );
   f2 ( );
   f3 ( );
   f4 ( );
}