c++ - 源不兼容是否总是意味着二进制不兼容?

标签 c++ binary-compatibility

欢迎提供任何示例来说明源兼容性被破坏但二进制兼容性得到维护。

最佳答案

旧版本:

struct inner {
  int bar;
}

struct foo {
  struct inner i;
};

void quux(struct foo *p);

新版本:

struct inner2 {
  int bar;
};

struct foo {
  struct inner2 i;
};

void quux(struct foo *p);

损坏的代码:

struct foo x;
struct inner *i = &x.i;
i->bar = 42;
quux(&x);

由于唯一的区别是结构的名称,并且内部结构的类型名称在编译期间被删除,因此不存在二进制不兼容性。

关于c++ - 源不兼容是否总是意味着二进制不兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1220304/

相关文章:

c++ - 自定义对象的 vector

c++ - 您能否(并且应该)消除使用 T 和 const 引用 T 的函数调用的歧义?

c++ - 使用 -g 标志编译带有 makefile 的单个 c++ 文件不起作用

C# 接口(interface)损坏,ABI

c++ - 将纯虚拟更改为虚拟并保持二进制兼容

c++ - 添加 move 构造函数会破坏二进制兼容性吗?

C++ 读取 CSV

c++ - 系统.DllNotFoundException : Unable to load DLL with dotnet core

linux - 我应该链接哪个 Linux 发行版以获得最佳二进制兼容性?

c - 在 32 位模式下使用 64 位 uint 作为指针值?