Modern C++

A hands-on, hardware-informed guide. Build a sound foundation, then learn how memory, compilers, and CPUs shape real program behavior.

CH 8

Error Handling, Tooling, and Multi-File Programs

8.1 Headers, ODR, Linkage, and Libraries

Organize multi-file programs without duplicate definitions, fragile globals, or ABI surprises.

8.2 Traditional Exceptions and Stack Unwinding Cost

Under the hood compiler exception lookups, binary size overheads, and the runtime latency of stack frame unwinding.

8.3 Exception Safety Guarantees and Copy & Swap

Basic, strong, and noexcept safety guarantees, and writing exception safe code using the copy and swap idiom.

8.4 The Noexcept Specifier and Vector Move Optimizations

Promising never to throw exceptions, compiler optimizations, and vector copy fallbacks.

8.5 Modern Error Handling: std::optional and std::expected

Monadic values transmission, returning nullable states, and returning value or error wrappers.

8.6 Assertions, Static Asserts, and Debug vs Release Verification

Compile time static checks, runtime sanity testing macros, and compiling out debugging overheads.

8.7 C++20 Modules and Translation Unit Isolation

Compiler isolated modules (export module, import) vs preprocessor includes, and building clean interfaces.

8.8 Build Systems: CMake and Dependency Management

Moving beyond single file compilation, CMake targets, build directories, and C++ package managers.

8.9 Profiling, Benchmarking, and Sanitizers

Instrumenting code for memory safety using AddressSanitizer (ASan) and measuring microsecond performance.

8.10 Practical Standard Library and C Interoperability

Use files, time, randomness, callable wrappers, and C APIs with explicit ownership and error boundaries.

FAQ

Who is this for?

Developers who want to demystify modern C++ and understand how source code maps to memory, compiled instructions, and real hardware constraints.

Is this beginner friendly?

Yes, for learners who are comfortable with basic programming logic. We begin with variables and functions, then introduce memory and performance concepts with practical guardrails.

What is the level?

It starts with the essentials and progresses to advanced systems topics such as atomics, memory resources, and performance measurement. Advanced sections assume steady practice.

What hardware topics does this cover?

CPU pipelines, caches, memory layout, binary data, SIMD, and concurrency hardware effects. It does not cover embedded firmware, GPU programming, or kernel development those need specialized material beyond this course.

Suggested learning path

Complete Chapters 0–8 and the Capstone (Chapter 10) for the beginner core path. Chapter 9 (threads, SIMD, coroutines) is advanced, take it after ownership, errors, and pointers feel solid. Chapter 11 (C++26 horizon) is experimental reference only.

That is it!

You now have a systems-oriented foundation for modern C++. Keep practicing with tests, sanitizers, real projects, and measurements on the platforms you target.