After reading Why do we need extern "C"{ #include <foo.h> } in C++? I concluded, including a header within the extern "C"-block is fine.
But I ran into problems with this constellation:
#ifdef __cplusplus
extern "C" {
#endif
#include "mixedstuff.h"
#ifdef __cplusplus
}
#endif
mixedstuff.h:
#ifdef __cplusplus
extern "C" {
#endif
#include "cstuff.h"
#ifdef __cplusplus
}
#include "cppstuff.h"
#endif
As one can see, I ended up with cppstuff.h
being included by the C++ compiler within the extern "C"
block. This caused a lot of errors, because many statements were just not possible with C-linkage.
The obvious solution is to #include mixedstuff.h
outside the extern "C"
block. But this requires me to look into each header to see if it is plain C, C++ or mixed.
From this I would recommend to make headers C++ aware, rather than including them in extern "C". Am I right, or is there a better way?