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

CWARN.INCL.NO_INTERFACE

Source file does not include its interface header

The CWARN.INCL.NO_INTERFACE checker is a coding style checker. It checks if every source file includes a header file with the same base name but a different extension.

Vulnerability and risk

It is good practice to separate a module's interface and its implementation, placing the implementation into a source file and the interface into a header file with the same base name. However, you should ensure that those files remain consistent during code changes. If a source file does not include its interface header, the inconsistency may show up at linking stage or even at run time.

Example

Suppose we have a custom memory allocator whose interface is described in file my_alloc.h and implementation is located inmy_alloc.c

my_alloc.h

void *my_alloc(int size);
void *my_realloc(void *allocated, int size);
void my_free(void *allovated);

my_alloc.c

void *my_alloc(int size) {
  // implementation of my_alloc function
}

void *my_realloc(void *allocated, int size) {
  // implementation of my_realloc function
}

void my_free(void *allovated) {
  // implementation of my_free function
}

Implementation and interface of my_alloc module can easily become inconsistent, while there still can be no errors during the compilation. To avoid this, add the missing include directive to the source file:

my_alloc.c

# include "my_alloc.h"

void *my_alloc(int size) {
  // implementation of my_alloc function
}

void *my_realloc(void *allocated, int size) {
  // implementation of my_realloc function
}

void my_free(void *allovated) {
  // implementation of my_free function
}