Yes, though macros can't be scoped, and namespaces won't work properly with C headers.
Another advantage is that modules are also effectively precompiled headers. You don't have to parse the header again and again, and all of its dependencies.
Precompiled headers is an interesting thought. They seem useful but how is it handled if you have a precompiled header and an include into that header is changed, does the compiler reliably detect there was a change and rebuild or is that something handled by the build tool?
The compiler doesn't detect such things. That is the job of the build tools. Just like the compiler won't check if an object file is out of date compared to the reference source file.
Modules are the same thing - you're 'precompiling' source file(s) into a module, which is effectively a trimmed-down precompiled header that also includes implementation with special syntax.
I actually have an urge to write a parser to go over the entirety of WinAPI, and generate module interfaces for it. Be much nicer than #include <Windows.h>.
Not sure if there is a 'standard' module file extension, yet... I know that MSVC uses .ixx, don't recall what Clang uses off-hand (I just use .ixx there, and am specific to the compiler about what I am doing).
Modules (and precompiled headers) are greatly dependent on build tool support. CMake's support for PCH is... not really existent. I know that build2 supports modules, unsure about PCH. MSBuild supports PCH, but doesn't have any proper support for modules - it can build them, but it has no way to resolve dependencies.
I appreciate all the details, but it seems we've now come full circle as based on everything you've said I'm still unsure what problem modules solve that good organizational practices in standard code development don't handle.
Modules are just fancier, standardized, more effective precompiled headers that also hide implementation details. You can accomplish the same other ways, though modules will likely be simpler and more effective.
1
u/oldprogrammer Jan 31 '19
Isn't that just the same thing that happens if you use C++ namespaces inside header files?