I’ve been working on a proposal for C++ that formalizes compatibility with C, due to some wording that seems to create issues.
There are a few parts, the first part defines that a Translation Unit may also be written in C, or in some other implementation-defined language, as well as noting a few things about C++ programs.
The 2nd part defines types which are “compatible” with C, non-exhaustively:
* The C++ bool and C _Bool types are compatible
* All fundamental types that exist in both languages are compatible
* The std::atomic_flag (C++11) and atomic_flag (C11) types are compatible
* Any std::atomic<T> (C++11) is compatible with _Atomic(U) (C11) if both are well-formed, and T is compatible with U (definitely the case if the atomics are lock-free, subject to change for non-lock-free types)
* trivial, standard-layout structure and union types are compatible, if they have the same name, and each member has the same name, and a compatible type, and either both not bitfields, or both bitfields with the same length.
* The memory_order enumerations are compatible
This would make some exemptions to declaration rules, allowing compatible types from other languages in place of exact types
The 3rd part defines library operations that are equivalent. I won’t list those, but for example, all “C” compatibility function calls are equivalent to the C counterpart.