C++ ABI

C++ applications often dependent on specific language support routines, say for throwing exceptions, or catching exceptions, and perhaps also dependent on features in the C++ Standard Library.

We need a uniform ABI to allow code to be compiled independently (into shared libraries, so files, etc.) and later linked and executed together!

For Linux, most compilers following Itanium ABI: https://itanium-cxx-abi.github.io/cxx-abi/abi.html

MSVC uses a different Microsoft-specific ABI.

Value categories

Qualifiers

a type qualifier is a keyword that is used to instruct the compiler that the type now qualified is special in some way.

In C++ there are 2 well-known qualifiers: const (including constexpr, etc.) and volatile. “cv-qualifier” is the term used to refer both as a whole.

Bitfields

to control the sizes in bits of class members

adjacent bitfield members are packed together to share 1 byte

struct S
{
  // will usually occupy 2 bytes:
  unsigned char b1 : 3; // 1st 3 bits (in 1st byte) are b1
  unsigned char    : 2; // next 2 bits (in 1st byte) are blocked out as unused
  // HERE: compiler-added padding to fulfill 1 byte
  unsigned char b2 : 6; // 6 bits for b2 - doesn't fit into the 1st byte
                        // => starts a 2nd byte
  unsigned char b3 : 2; // 2 bits for b3 - next (and final) bits in the 2nd byte
};

struct T
{
    // will usually occupy 2 bytes:
    // 3 bits: value of b1
    // 5 bits: unused
    // 2 bits: value of b2
    // 6 bits: unused
    unsigned char b1 : 3;
    unsigned char :0; // unnamed bitfield size zero forces to break up padding
    unsigned char b2 : 2;
};