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.ONEDEFRULE.VAR

Global variable definition in a header file.

MISRA-C Rule 8.5 (required): There shall be no definitions of objects or functions in a header file.

This rule is also covered by MISRA.ONEDEFRULE.FUNC.

Header files should be used to declare objects, functions, typedefs, and macros. Header files shall not contain or produce definitions of objects or functions (or fragment of functions or objects) that occupy storage. This makes it clear that only C files contain executable source code and that header files only contain declarations. A "header file" is defined as any file that is included via the #include directive, regardless of name or suffix.

MISRA-C++ Rule 3-1-1 (required): It shall be possible to include any header file in multiple translation units without violating the One Definition Rule.

This rule is also covered by MISRA.ONEDEFRULE.FUNC.

Rationale

Header files should be used to declare objects, functions, inline functions, function templates, typedefs, macros, classes, and class templates and shall not contain or produce definitions of objects or functions (or fragment of functions or objects) that occupy storage.

A header file is considered to be any file that is included via the #include directive, regardless of name or suffix.

Example

// a.h
       void f1 ( );    // Compliant
       void f2 ( ) { } // Non-compliant
inline void f3 ( ) { } // Compliant
template <typename T>
void f4 ( T ) { }      // Compliant

int32_t a;             // Non-compliant

// a.cpp
#include "a.h"