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

UnreliableCode Community

Developer Research, Reverse Engineering & Coding Community

Question

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

GarbageCollector
CLR Internals
MEMBER
Rep: 255
Join Date: Oct 2023
Posts: 7
Thanks: 50
3y ago · Sep 7, 2022 12:24 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?
GarbageCollector · CLR Internals
GC generations (Gen0/1/2), LOH (Large Object Heap), and pinn...
The following users thanked GarbageCollector for this post:
PInvokeMaster
Interoperability Specialist
VIP
Rep: 247
Join Date: Feb 2021
Posts: 6
Thanks: 83
3y ago · Sep 7, 2022 3:38 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.
PInvokeMaster · Interoperability Specialist
P/Invoke, NativeAOT, C# to C++ native interoperability, and ...
EventDriven
Reactive Extensions
MEMBER
Rep: 160
Join Date: Sep 2022
Posts: 6
Thanks: 66
3y ago · Sep 7, 2022 5:38 PM
#3
Build times on large projects drop dramatically because header parsing is no longer duplicated across every single .cpp file.
EventDriven · Reactive Extensions
Rx.NET, event buses, and asynchronous message queues in C#....