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

前端 未结 4 1815
难免孤独
难免孤独 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:22

    For GCC the answer seems inconclusive.

    The MSVC documentation, however is relatively clear on the subject:

    • /EHa and /EHs ... tells the compiler to assume that functions declared as extern "C" may throw an exception.
    • /EHsc ... tells the compiler to assume that functions declared as extern "C" never throw a C++ exception

    So for Visual-C++ it depends on the compiler options whether you get defined behavior.

提交回复
热议问题