Does extern “C” force limitations on my code?

后端 未结 2 1526
既然无缘
既然无缘 2021-01-20 04:17

Does the standard say anything about limitations on functions used with extern \"C\"? In a questions of mine that makes no sense to anyone else. It appears that

相关标签:
2条回答
  • 2021-01-20 04:47

    You can't have extern 'c' that isn't compatible with 'c' - that means no default parameters and no overloaded functions

    0 讨论(0)
  • 2021-01-20 04:57

    I believe the answer to this question gives a good overview of the requirements on extern "c" linkage. The issue I believe you are running into is the last item:

    Linkage from C++ to objects defined in other languages and to objects defined in C++ from other languages is implementation-defined and language-dependent. Only where the object layout strategies of two language implementations are similar enough can such linkage be achieved.

    Since your function is returning a class it will be implementation-defined depending on the definition of that class. This explains why it works in one compiler but not another.

    The C++ faq has a few relevant sections on this as well.

    0 讨论(0)
提交回复
热议问题