I have a class with number of private data members (some of them static), accessed by virtual and non-virtual member functions. There's no inline functions and no friend classes.
class A
{
int number;
string str;
static const int static_const_number;
bool b;
public:
A();
virtual ~A();
public:
// got virtual and non-virtual functions, working with these memebers
virtual void func1();
void func2();
// no inline functions or friends
};
Does changing the order of private data members breaks ABI in this case?
class A
{
string str;
static const int static_const_number;
int number; // <-- integer member moved here
bool b;
...
};
Edit
The types are not changed, only the order of the members. No bit flags are used as well.
The code is used as shared library, there's no static linking to this code.
I'm on Linux and the compilers are gcc-3.4.3 and gcc-4.1
ABI break happens when one binary, e.g. shared object, uses a different ABI when calling functions on another shared object. If both binaries are not ABI compatible, the interpretation of the bytes would be wrong.
These details are defined as the compiler Application Binary Interface, or ABI. From GCC version 3 onwards the GNU C++ compiler uses an industry-standard C++ ABI, the Itanium C++ ABI. The GNU C++ compiler, g++, has a compiler command line option to switch between various different C++ ABIs.
As C++ evolved over the years, the Application Binary Interface (ABI) used by a compiler often needed changes to support new or evolving language features. Consequently, programmers were expected to recompile all their binaries with every new compiler release.
It might, yes, if for no other reason than that the size of A
could be different due to differences in the location and number of padding bytes between the data members.
According to KDE Policies/Binary Compatibility Issues With C++ you cannot do it without breaking binary compatibility. However, as their disclaimer states, some of the advices they give in "you cannot..." part are compiler dependent, so you might get away with that change (although it's not very likely).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With