Does extern "C" limit my code?

Does the standard talk about restrictions on functions used with extern "C"

? In my problems that don't make sense to anyone else . It looks like when I have a complex gcc class breaks (runtime oddities / errors) if I call a non-default constructor (something with a parameter I believe) and msvc seems to break if it's not a POD (however i can still use my constructors and it worked great).

I suspect all undefined behavior is happening because the C library calls my C ++, which returns a type that is exactly the size of a pointer, but has operator overloads and constructors. I don't know why this is happening and gcc of course doesn't give me any warnings.

Does extern "C" limit my code? All I know are exceptions that cannot get through, which is fine since I am not using them in this code. What are the other restrictions?

-edit- Related: Reproducible: Why is passing this object to C breaking my code?

+3


source to share


2 answers


You cannot have extern 'c' which is incompatible with 'c' - this means no default parameters and no overloaded functions



+5


source


I believe the answer to this question gives a good overview of the external communication requirements "c". The problem that I believe you are working on is the last item:

Linking from C ++ to objects defined in other languages ​​and objects defined in C ++ from other languages ​​is implementation-defined and language-dependent. Only where the object placement strategies of the two language implementations are sufficiently similar can such a relationship be achieved.



Since your function returns 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 contains several relevant sections.

+3


source







All Articles