Home / Forums / What are C++20 Modules and how do they replace traditional header files? [Discussion #7]

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Question

What are C++20 Modules and how do they replace traditional header files? [Discussion #7]

MemoryLeaker
C++ Enthusiast
VIP
Rep: 182
Join Date: Sep 2022
Posts: 6
Thanks: 20
3y ago · Sep 16, 2022 6:00 PM
#1
How do C++20 Modules (.ixx / .cppm) compare to traditional .h and .cpp file structures? Do they actually eliminate header guards and speed up build times?
MemoryLeaker · C++ Enthusiast
Always remembering to delete my heap pointers... most of the...
The following users thanked MemoryLeaker for this post:
SourceGenDev
C# Tooling
MEMBER
Rep: 158
Join Date: Jan 2020
Posts: 8
Thanks: 79
3y ago · Sep 16, 2022 9:14 PM
#2
Modules compile once into a binary Module Interface File (BMI / IFC). When another translation unit imports the module (import MyModule;), the compiler loads the pre-parsed AST directly instead of re-tokenizing thousands of lines of text! Macro leaks across files are completely prevented.
SourceGenDev · C# Tooling
Metaprogramming with C# 9+ Source Generators and Roslyn Anal...
SimdSamurai
AVX-512 & SSE
MEMBER
Rep: 285
Join Date: Aug 2021
Posts: 7
Thanks: 36
3y ago · Sep 16, 2022 11:14 PM
#3
Build times on large projects drop dramatically because header parsing is no longer duplicated across every single .cpp file.
SimdSamurai · AVX-512 & SSE
Vectorizing matrix multiplications and particle engines with...