GeneralPurpose-LinkageMismatch¶
Do not include C header files into C++ without ‘extern “C”’
Required inputs: IR
extern "C")
may have incompatible meanings, i.e. functions have different calling conventions.
Bad code (mixed linkage):
// foo.h
int foo(int); // ERROR: This declaration has different meanings in C and C++
// (name mangling used only when included from C++)
// foo.cpp
#include "foo.h"
// foo.c
#include "foo.h"
Good code:
// foo.h
#ifdef __cplusplus
extern "C" {
#endif
int foo(int); // OK: extern "C" ensures that this declaration has the same meaning
// in C and C++
#ifdef __cplusplus
}
#endif
Good code:
// foo.h
int foo(int);
// foo.cpp
extern "C" {
// OK: extern "C" ensures that this declaration has the same meaning in C and C++
#include "foo.h"
}
// foo.c
#include "foo.h"
Possible Messages
Key |
Text |
Severity |
Disabled |
|---|---|---|---|
linkage_mismatch |
This declaration has different meanings in C and C++ (name mangling used only when included from C++. Did you forget to add ‘extern “C”’ when including C headers into C++? |
None |
False |
Options
This rule shares the following common options: exclude_in_macros, exclude_messages_in_system_headers, excludes, extend_exclude_to_macro_invocations, includes, justification_checker, languages, post_processing, provider, report_at, severity
The following places define options that affect this rule: Stylechecks, Analysis-GlobalOptions
This rule has no individual options.