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
}