4 ms·
> Have you got an example where pure addition breaks the existing compatibility? With c/c++ additions can break binary compatibility can't they? Adding a field
by flukus 10y ago
> Have you got an example where pure addition breaks the existing compatibility?
With c/c++ additions can break binary compatibility can't they? Adding a field to a struct for instance will mean existing code that does a malloc for that struct won't allocate coorectly. I think there are a million other cases to consider too.
- netheril96 10y ago> Adding a field to a struct for instance will mean existing code that does a malloc for that struct won't allocate coorectly. Really? Do you ever call `malloc(4)` instead of `malloc(sizeof(int))` or `malloc(sizeof(*ptr))`?
- viraptor 10y agoI don't think so. Have you got an example?
- flukus 10y agoJust updated with one.
- viraptor 10y agoNormally in a library you'd provide functions that allocate and free structures defined by that library. That's how successful C libraries do it. I think semver covers this pretty well actually. The public API is not just the function signatures, but basically anything that makes your API - whether it's code or documentation. So either: - your structs in the library are opaque and the library handles all the memory management itself - addition of fields is backwards compatible, or - your structs are open and your functions expect the structs from outside - addition of fields is not backwards compatible The second one is still falls under "Major version X (X.y.z | X > 0) MUST be incremented if any backwards incompatible changes are introduced to the public API." To make a comparison in a dynamic language: you've got public function `f(d)` where `d` is some dictionary with elements `a` and `b`. Now in the next version you start to require `c` - same signature in the code, but it's not backwards compatible. It's still a public API, even if defined by the documentation.
- flukus 10y ago> That's how successful C libraries do it. What about c++? Object allocation is always handled by new on the consumer side isn't it? Also in C, does the order of function declarations matter?
- viraptor 10y agoI don't do C++ normally, but the situation seems similar. There's http://wiki.c2.com/?PimplIdiom http://wiki.c2.com/?PimplIdiom for opaque objects, so you don't have to make their members part of the public API. But for things you do want to make public it's the same solution - make it a your public API by documenting it. If you know it breaks compatibility, it requires major version bump. And no, after compilation, I don't believe the symbol order matters.
- flukus 10y agoThe pimpl method looks like it ads a level of indirection to every private member access. Is that an issue in practice?
- slavik81 10y agoQt uses it extensively. For big, complex objects like QTextEdit it's probably the least of your concerns, but they do avoid it for simple value types like QPoint.
- flukus 10y agoA good chunk of these questions I'm asking are because I half remember Qt's binary compatibility guidelines from when I did an internship at Trolltech many years ago :) A similar list is here: https://community.kde.org/Policies/Binary_Compatibility_Issues_With_C%2B%2B https://community.kde.org/Policies/Binary_Compatibility_Issu... . It looks like the virtual function restrictions are what I was talking about, that's where pure additions can break compatibility.
- fjdlwlv 10y agoC/C++ is hopeless for binary compatibility, under any version scheme
- slavik81 10y agoQt is C++ and only breaks binary compatability on major version changes (~6 years apart). It's hard, but certainly not hopeless.
- wahern 10y agoLinux's support for ELF symbol versioning makes maintaining binary compatibility of C libraries easier than perhaps any other platform or language. It's patterned after Solaris' ELF symbol versioning, but more powerful. glibc uses it extensively, but alas few other people know about it. Theoretically languages, like Rust, which compile to ELF executables could leverage the capability. But none do. There are a series of posts from a libvirt developer which explain some of the mechanics: https://www.berrange.com/posts/2011/01/13/versioning-in-the-libvirt-library/ I personally don't bother with semantic versioning at all. Where ABI compatibility matters, I'll commit to maintaining backward ABI compatibility in perpetuity using symbol versioning.[1] And maintaining backwards API compatibility is something I try to commit to as a matter of course; if I can't then I make sure builds will break loudly. I don't begrudge people using semantic versioning, I don't just don't think it's the best approach for most cases. It's just one of several crappy choices. But at least with C on Linux, ELF symbol versioning is a slam dunk when you're serious about the matter. [1] I usually avoid depending on proprietary platform features. But this is the one area I'm comfortable and eager to lean on Linux.