Re:Hourglass Interfaces for C++ APIs
by captainmuon on Friday September 12, 2014 @05:20PM
(#8310529)
Wow, that seems really useful! I've been wondering for a while how to do C++ libraries best. One thing I never figured out were how to expose lists/vectors/containers, I never thought of using callbacks for that.
By the way, the restriction to a minimal subset of C++ like in this technique explains a lot of why COM is the wierd way it is. E.g. only simple types for parameters; no exceptions, instead you return HRESULTS, and so on. COM does one thing that goes beyond plain C: Interestingly, it uses the one part of the C++ ABI that is stable (whether per standard or per accident I don't know): that vtables always have a certain simple layout, and given a pointer and an interface you can predict where the virtual function pointer will sit.
By the way, the restriction to a minimal subset of C++ like in this technique explains a lot of why COM is the wierd way it is. E.g. only simple types for parameters; no exceptions, instead you return HRESULTS, and so on. COM does one thing that goes beyond plain C: Interestingly, it uses the one part of the C++ ABI that is stable (whether per standard or per accident I don't know): that vtables always have a certain simple layout, and given a pointer and an interface you can predict where the virtual function pointer will sit.