3 ms·
I don't really understand why you can't expose a stable ABI right from the first C++ layer. It shouldn't be any harder than making such ABI in the third layer,
by shmerl 13y ago
I don't really understand why you can't expose a stable ABI right from the first C++ layer. It shouldn't be any harder than making such ABI in the third layer, and will avoid many extra function calls which don't come for free.
- piokuc 13y agoIt's enough to add a member to a class to break its ABI compatibility. It's possible to expose a stable C++ API but that normally requires extra classes implementing the PIMPL idiom, so basically the 3rd, C++ layer described in the article. PIMPL doesn't require the C API (2nd layer), of course, but if you need the C API anyway, for calling your lib from scripting languages, for example, then the 3 layers make sense. Lots of tedious work, but that's C++...
- shmerl 13y agoWhat I mean is, instead of making [Core C++ library] -> [stable C interface] -> [stable C++ interface] one could make both directly: [Core C++ library] -> [stable C interface] [Core C++ library] -> [stable C++ interface] That would avoid extra overheard in the last case.
- piokuc 13y agoAs far as the number of layers is concerned it's the same. The advantage of writing the C++ stable API on top of C API is that both C and (stable) C++ API have the same functionality/semantics - if you write those two separately on top of the primary C++ API they can easily diverge.