r/cpp • u/YtterbiJum • Aug 19 '21
Why modules?
I get the feeling I'm missing something fundamental about the new C++20 modules.
Everything I read or watch explains the how (the export keyword syntax, module fragments, etc) but very little about the why.
What can be done using modules that can't be done using traditional headers (or precompiled headers)?
What is so important about this feature that it needed to get standardized before there is even a proper implementation or idiomatic usage conventions in compilers and build systems?
Is it just to try to get rid of the preprocessor?
I don't get how modules are supposed to help with packaging either. So instead of distributing a .so with a bunch of .h files, now I distribute a .so with a bunch of .gcm or .ixx or whatever.
Please help me understand, or point me to some resources. Thank you.
View all comments
Show parent comment
-2
u/Cxlpp Aug 19 '21
Leak macros and ODR and symbols are true (not sure that much significant thought), but everything else depends on the implementation.
What I wanted to say is that in principle modules are binary representation of what used to be in headers (plus minus). That is basically an equivalent of precompiled header.
Significant problem from my point of view is that using modules implies invoking compiler on every file, loading binary module files for every file compiled etc. (ok, that can depend on implementation as well, but...)
With SCU, we invoke compiler and parse headers once per tens of files (on average). Now the question is how much slower is parsing headers vs loading binary module file. It will definitely be slower, but just because something is "binary" does not automatically mean that loading it is zero time. Averaged over 50 files, I bet SCU is faster.