Can C++ functions marked as Extern "C" throw? -
i've got c++ functions want declare using extern "c" though called in c++ code. yes, know strange it's consistency since have mixed c , c++ declarations. want make sure declaring c++ function extern "c" won't affect behavior of throwing.
it this:
extern "c" void foo() {throw exception;} int bar() { try { foo(); } catch (exception e) { return 1; } }
"can c++ functions marked extern “c” throw?"
yes, in sense neither language nor compiler prevent doing so.
no, in sense if throw, undefined behaviour, c++ exception crosses language boundaries.
in practice: not it. catch exception , translate error code, or means other language can understand.
so bottomline is: do not throw exception functions marked extern "c".
Comments
Post a Comment