I have searched some articles about C++ (COM-like) ABI Interface of DLL, for example: "Exporting C++ classes from a DLL" and "Binary-compatible C++ Interfaces", they're very nice and helpful, but they didn't talk about namespace.
Does namespace break ABI ?
namespace Foo {
class Listener {
virtual void e1() = 0;
virtual void e2() = 0;
};
class Interface {
virtual void setListener(Listener*) = 0;
virtual int f1() = 0;
virtual int f2() = 0;
};
}
extern "C" Foo::Interface* SOME_API createFooInterface();
I have no idea, does it work ?
Sorry, I'm just not being clear, my English writing ability is not very well.
In my code snippet, extern "C" is preventing name mangling in C++ DLL exports, name mangling is incompatible between C++ compilers, the two articles mentioned above are talking about this question.
My meaning about "break ABI" is: I can do this in MSVC, I can use namespace for my C++ interface classes, I can export a DLL from this code, but I am not sure this interface is still ABI - A Binary-compatible interface between compilers, it's not about two namespaces, it's about two or more compilers.
Foo::Interface *
be flattened to "C" linkage, i.e. without name mangling, and still be distinguishable from e.g.Bar::Interface *
? How could the C functioncreateFooInterface()
return a C++ construct (a namespaced type)? – DevSolarextern "C"
when discussing C++ ABI's, though. That defeats the point. – MSalters