6 ms·
It'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 impleme
by piokuc 12y ago
It'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 12y 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 12y 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.