Using C wrapper of C++ code for ABI stability?

Viewed 168

In his talk Jason Turner proposed to break the C++ ABI to keep the language moving forward. He also mentioned that if needed due to compatibility reasons, C++ ABI changes can be isolated by wrapping a C++ library into a C library.

A relevant screenshot at 27:30:

C wrapper illustration

Here "BinaryLibrary" and "Old C++ stdlib" use an old ABI, and "NewExecutable" uses a hypothetical updated ABI.

As far as I understand, this works since old C++ ABI of "BinaryLibrary" gets baked into a separate binary with a more stable interface.

But what makes C a good alternative? Can't its ABI change as well?

1 Answers

Can the C ABI change? Well, not easily. There have been occasional changes on some platforms, but so many systems and languages are built using the C ABI as a public interface that it has to be quite stable. Many languages have a C FFI which allows them to call C functions, and changing the C ABI would break those. And the C ABI is a common way of interacting with the operating system, e.g. to open files or send messages, so it's used by many language implementations (e.g. interpreters and standard libraries).

Note that the C ABI is not part of the C standard. Each platform or system can define its own C ABI. So while it tends to be stable over time on a given platform, it is not consistent across all platforms.

Related