English
Summary
Conclusions
Splitting code into files and libraries helps make the boundaries of responsibility explicit. A header describes an interface for textual inclusion; a module provides controlled exports and import dependencies. Both approaches require correct linking and consistent options. An automated build description and tests make a project reproducible, and checking specific features lets you use modern C++ without assuming full support for the standard.
Self-check questions
- How does a declaration differ from a definition?
- What exactly does an include guard protect against, and what does it not guarantee?
- Why do
externin a header and a definition in a.cppfile form one object? - Why can
staticin a header change the behavior of a shared counter? - What is the language role of
inline, apart from its historical connection with optimization? - Why should you not open the whole
stdnamespace in a public header? - Which artifacts are needed to use a static library?
- How does a module export differ from a Windows DLL export?
- What roles do
.ixx,.ifc, and.objfiles play? - What is the global module fragment
module;for? - How does
import :partdiffer fromexport import :part? - Why does the compilation order of modules depend on the import graph?
- Why does
import stdnot replace a header with the required macros? - How do configure, build, and test differ in CMake?
- Why does the presence of the old
executionmacro not prove C++26 support?
Review questions for the lab
- Which files does the client’s compiler need, and which does the linker need?
- Why does an include guard not eliminate ODR violations between different
.cppfiles? - How do an external variable, the internal state of a file, and an
inlinevariable differ? - Why is a module
exportnot a Windows DLL export? - What roles do the primary interface, a partition, and a module implementation unit play?
- Why do you distinguish the names of the object files of the interface and the implementation?
- Why can a ready-made IFC not be moved arbitrarily between toolsets?
- How does CMake determine the compilation order of a client and a module?
- Why should mandatory tests not rely only on
assert? - Which check proves that the required C++26 feature is available in your project?
Useful links
- Translation units and linkage: https://learn.microsoft.com/cpp/cpp/program-and-linkage-cpp.
- Named modules: https://learn.microsoft.com/cpp/cpp/tutorial-named-modules-cpp.
- The standard library module: https://learn.microsoft.com/cpp/cpp/tutorial-import-stl-named-module.
- Modules in CMake: https://cmake.org/cmake/help/latest/manual/cmake-cxxmodules.7.html.
- MSVC support status: https://learn.microsoft.com/cpp/overview/visual-cpp-language-conformance.