Fragile ABI

dsimcha dsimcha at yahoo.com
Thu Aug 16 17:01:51 PDT 2012


On Thursday, 16 August 2012 at 14:58:23 UTC, R Grocott wrote:
> C++'s fragile ABI makes it very difficult to write class 
> libraries without some sort of workaround. For example, 
> RapidXML and AGG are distributed as source code; GDI+ is a 
> header-only wrapper over an underlying C interface; and Qt 
> makes heavy use of the Pimpl idiom, which makes its source code 
> much more complex than it needs to be. This is also a major 
> problem for any program which wants to expose a plugin API.

Since pimpl is useful but messy, given D's metaprogramming 
capabilities, maybe what we need is a Pimpl template in Phobos:

// The implementation struct.
struct SImpl {
    int a, b, c;

    void fun() {}
}

// Automatically generate code for the Pimpl wrapper.
alias Pimpl!SImpl S;

auto s = new S;

On the other hand, IIUC Pimpl doesn't solve the vtable part of 
the problem, only the data members part.  (Correct me if I'm 
wrong here, since I admit to knowing very little about the 
fragile ABI problem or its workarounds.)


More information about the Digitalmars-d mailing list