If you are externalizing your functions, variables and struct with
extern "C" { int global; }
in the header files and
extern "C" int global = 20;
in your C ++ code, it will be used from C code. The same rule applies to functions.
You can even call methods with appropriate prototypes. For example:
class C { public: c(int); int get(); };
C-Wrapper in your .cpp might look like this:
extern "C" void * createC(int i) { return (void *) new C(i); } extern "C" int Cget(void *o) { return ((C *)o)->get(); }
Patrick B.
source share