Is there any difference between the global module fragment and the `extern "C++"` blocks?

1 day ago 1
ARTICLE AD BOX

When a module needs to include a header, the following usually doesn't work, since the header contents get attached to the module:

export module A; #include <iostream> // Wrong

Including in the global module fragment does work, as it attaches the header contents to the global module:

module; #include <iostream> export module A;

Including in an extern "C++" block also seems to work:

export module A; extern "C++" { #include <iostream> }

Some compilers warn about the latter, but that seems to be a generic warning for includes, that fails to check for extern "C++" above the include.

Is there any difference between the last two snippets? Other than the warnings, is there any reason to prefer one or the other?

Read Entire Article