Discord · CS Fundamentals
Explain C++ alignment and ABI stability
TrueInterview
October 7, 2026 · 1 min read
You are in an interview for a senior C++ / systems position. The interviewer poses two low-level fundamentals questions:
- C++ memory alignment and padding
- Explain the meaning of memory alignment in C and C++.
- Describe what padding is within structs/classes and at their end.
- Use a small example to show how member order can alter a struct's
sizeofbecause of padding. - Discuss why alignment and padding are needed (performance, hardware constraints) and the problems they can introduce (e.g., unexpected struct size, binary compatibility issues, undefined behavior when misaligned).
- Mention common ways to inspect or control layout when it is absolutely necessary (e.g., compiler-specific pragmas/attributes,
static_assert(sizeof(...)), etc.), and the risks involved.
- ABI (Application Binary Interface) and its instability
- Define an ABI (Application Binary Interface) and explain how it differs from a source-level API.
- Explain what an ABI covers (e.g., calling conventions, data layout, alignment, name mangling, exception handling, vtable layout).
- Explain why the C++ ABI is frequently not stable across different compilers or even different versions of the same compiler, whereas C ABIs tend to be far more stable.
- Give concrete examples of practical problems caused by ABI instability (e.g., linking a program against a shared library built with a different compiler/version, plugin systems, distributing precompiled libraries).
- Describe common engineering strategies for mitigating ABI issues in C++ (e.g., using a stable C interface boundary with
extern "C", avoiding STL types in public ABIs, the PImpl idiom, rebuilding all components with the same toolchain).
Answer in a way that demonstrates deep understanding of low-level details and practical trade-offs.
Overview: This question assesses mastery of C++ low-level memory concepts—memory alignment, padding, and struct/class layout—and understanding of ABI stability, including calling conventions, name mangling, vtable layout, and other binary compatibility concerns, reflecting competence in systems-level C++ and binary interfacing.
Loading comments…