Reputation:
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 when i have a complex class gcc breaks (runtime oddities/errors) if i call a non default constructor (anything with a parameter i believe) and msvc seems to break if it isn't a POD (however i could still use my constructors and it ran fine).
I suspect all the undefined behavior happens because a C library is calling my C++ which returns a type that is exactly the size of a pointer but has operator overloading and constructors. I don't know why it happens and gcc certainly doesn't give me any warnings.
Does extern "C" force limitations on my code? All i know is exceptions can't go through them which is fine as i don't use them in this code. What are other limitations?
-edit- Related: Reproducible: Why does passing this object in C break my code?
Upvotes: 3
Views: 1697
Reputation: 6204
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.
Upvotes: 3
Reputation: 96119
You can't have extern 'c' that isn't compatible with 'c' - that means no default parameters and no overloaded functions
Upvotes: 6