0

I want to write one part of my program in C++, and part of it in C or some other language. How can I do that? Calling a C++ function from C is trivial, and exceptions seem like the biggest obstacle here.

puppon -su
  • 137
  • 2
  • 8
  • 2
    C can't handle exceptions. Make C++ handle them. – nwp Nov 23 '17 at 14:50
  • 1
    As a general rule, don't throw past your c++ module's interface. – François Andrieux Nov 23 '17 at 14:51
  • You can create C functions that wrap your C++ methods. The first param of the wrapper functions could be a void pointer to accept the C++ object, which you can cast to the object type within the function. Within the function put a try/catch around the method you want to call. Have the function return a value indicating whether the function succeeded or not. THis way you can make the features of your class accessible to plain C code. You also need to use extern "C" in the header to ensure the function signatures are C compatible. – Todd Nov 23 '17 at 14:56

0 Answers0