If a function shall be used form C
and C++
code the declaration of this function (usually in a header file) has to be surrounded by
#ifdef __cplusplus
extern "C" {
#endif
// function declarations
#ifdef __cplusplus
}
#endif
We are merging for C
to C++
and now we have to introduce this into a lot of header files.
Almost all headers now have these line at the very top and bottom, respectively.
This reminds me of header guards.
#ifndef SOMESYMBOL
#define SOMESYMBOL
// content of the header file
#endif
Is there a way (like #pragma once
) to declare the extern C
linkage only at the top? This linkage behaviour should hold for the entire file. I like to avoid the closing bracket at the end.