Can C++ functions marked as Extern “C” throw?

前端 未结 4 1830
难免孤独
难免孤独 2020-12-30 22:52

I\'ve got C++ functions that I want to declare using extern \"C\" even though they are only called in C++ code. Yes, I know this is strange but it\'s something

4条回答
  •  庸人自扰
    2020-12-30 23:35

    "Can C++ functions marked as Extern “C” throw?"

    Yes, in the sense that neither the language nor the compiler will prevent you from doing so.

    No, in the sense that if you throw, it would be an undefined behaviour, as the C++ exception crosses language boundaries.

    In practice: do not do it. Catch the exception and translate it into an error code, or a means the other language can understand.

    So the bottomline is: do NOT throw exception from functions marked as extern "C".

提交回复
热议问题