更改类私有数据成员的顺序是否会破坏ABI

Dmi*_*kov 9 c++ linux gcc shared-libraries binary-compatibility

我有一个包含多个私有数据成员的类(其中一些是静态的),由虚拟和非虚拟成员函数访问.没有内联函数,也没有朋友类.

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
};
Run Code Online (Sandbox Code Playgroud)

在这种情况下,更改私有数据成员的顺序是否会破坏ABI?

class A
{
    string str;
    static const int static_const_number;
    int number; // <--   integer member moved here
    bool b;
    ...
};
Run Code Online (Sandbox Code Playgroud)


编辑
类型不会更改,只会更改成员的顺序.也没有使用位标志.代码用作共享库,没有静态链接到此代码.我在Linux上,编译器是gcc-3.4.3和gcc-4.1

Jam*_*lis 12

可能,是的,如果没有其他原因,A由于数据成员之间的填充字节的位置和数量的差异,大小可能不同.


cha*_*lup 5

根据KDE策略/二进制兼容性问题使用C++,如果不打破二进制兼容性,就无法做到这一点.但是,正如他们的免责声明所述,他们在"你不能......"部分提供的一些建议依赖于编译器,因此你可能会摒弃这种变化(虽然不太可能).