The file extensions are conventions/conveniences to make it easier for us
hoo-mans to differentiate what a file contains. To the preprocessor/compiler a file extension doesn't mean anything.
When it comes to modules everyone but MS so far is leaning towards using .cppm to designate a module interface file, .cpp for an internal partition file OR module code (/interface, the same as .cppm)
MS likes .ixx for a module interface file, though Visual Studio recognizes .cppm.
To get VS to recognize a file as an internal partition one of the file's properties must be manually modified in the IDE. I don't know how to do this with the command-line compiling tools.
The VS IDE sorts the files in Solution Explorer based on the file's extension, for easier management of a project with multiple files. Console-mode programs with routine file extensions get sorted into header and source file sub-categories.
Module interface and partition files are sorted into the source file sub-category exclusively.
VS treats even module-free C++ code as defaulted to a module interface file, that can be set to compile as C++ code manually.
1 2 3 4 5 6
|
#include <iostream>
int main()
{
std::cout << "Hello World!\n";
}
|
When compiled as a module interface file there are additional compilation steps that occur. When the above snippet is compiled as C++ code (/TP):
Build started...
1>------ Build started: Project: Project1, Configuration: Debug x64 ------
1>Source.cpp
1>Project1.vcxproj -> C:\Programming\My Projects\Project1\x64\Debug\Project1.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== |
When compiled as C++ module code:
Build started...
1>------ Build started: Project: Project1, Configuration: Debug x64 ------
1>Scanning sources for module dependencies...
1>Source.cpp
1>Compiling...
1>Source.cpp
1>Project1.vcxproj -> C:\Programming\My Projects\Project1\x64\Debug\Project1.exe
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ========== |
Importing stdlib library headers as modules (
import <iostream>;
instead of
#include <iostream>
) and custom created module interface/partition files adds even more module dependency scanning. Even the stdlib modules require being compiled the first time or during a complete rebuild.
Headers and module interface files are similar in what they do, but they are most certainly not the same.
Tattoo that on the back of your eyelids and learning to use modules will become easier. Still a major shift of thinking, but not as frustrating as thinking modules and headers are the same.
No other compiler at present other than VS supports modules, so I can't say how they would work when consuming modules.
Personal tastes...
I prefer .h/.c for C, .hpp/.cpp for no modules C++.
When it comes to C++ code using modules it is .cppm and .cpp. I loath .ixx and will probably never use it.
Of course, using modules requires the C++ language standard for the entire solution/project to be set to C++20 (std:c++20) or higher. Higher at this time is std:c++latest. When VS implements C++23 then eventually having C++23 as a language standard option should become available.