Need for Modules
Explore the reasons behind the introduction of modules in C++20. Understand the limitations of the traditional build process involving preprocessing, compilation, and linking, and see how modules address issues like repeated header inclusion, macro conflicts, and multiple symbol definitions to improve compilation efficiency and code management.
Modules are one of the four big features of C++20: concepts, modules, ranges, and coroutines. Modules promise a lot: shorter compile times, macro isolation, abolishing header files, and avoiding ugly workarounds. Before I present the advantages of modules, I want to step back and explain their benefits.
Why do we need modules?
Let me start with a simple executable. For obvious reasons, I create a “Hello World” program.
Making an executable main out of the program main.cpp with GCC increases its size by factor .
#include <iostream>
int main() {
std::cout << "Hello World" << '\n';
}The numbers and ...