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.STATIC.REDECL

Function or object redeclaration does not include static modifier

MISRA C 2012 Rule 8.8: The static storage class specifier shall be used in all declarations of objects and functions that have internal linkage

Category: Required

Analysis: Decidable, Single Translation Unit

Applies to: C90, C99

Amplification

Since definitions are also declarations, this rule applies equally to definitions.

Rationale

The Standard states that if an object or function is declared with the extern storage class specifier and another declaration of the object or function is already visible, the linkage is that specified by the earlier declaration. This can be confusing because it might be expected that the extern storage class specifier creates external linkage. The static storage class specifier shall therefore be consistently applied to objects and functions with internal linkage.

Example

static int32_t x = 0;                /* definition: internal linkage   */ 
extern int32_t x;                    /* Non-compliant                  */

static int32_t f ( void );           /* declaration: inte rnal linkage */ 
int32_t f ( void )                   /* Non-compliant                  */ 
{
  return 1; 
}

static int32_t g ( void );           /* declaration: internal linkage  */ 
extern int32_t g ( void )            /* Non-compliant                  */ 
{
return 1; 
}

MISRA-C 2004 Rule 8.11 (required): The static storage class specifier shall be used in definitions and declarations of objects and functions that have internal linkage

Function or object redeclaration does not include 'static' modifier.

The static and extern storage class specifiers can be a source of confusion. It is good practice to apply the static keyword consistently to all declarations of objects and functions with internal linkage.

MISRA-C++ 2008 Rule 3-3-2 (required): If a function has internal linkage then all redeclarations shall include the static storage class specifier.

Rationale

If the declaration of a function includes the static storage class specifier, then it has internal linkage.

A re-declaration of such a function is not required to have the static keyword, but it will still have internal linkage. However, this is implicit and may not be obvious to a developer. It is therefore good practice to apply the static keyword consistently so that the linkage is explicitly stated.

Example

static void f1 ( );
static void f2 ( );
       void f1 ( ) { }    // Non-compliant
static void f2 ( ) { }    // Compliant