CKTIS / C++
export — exposing a module interface
The `export` keyword marks a module interface unit, exposes declarations to importers, or re-exports an import. Writing `export module M;` alone does not automatically export all subsequent declarations.
Version: C++23; repository compiler flag, production runtime not attested
Syntax
export module M;
export declaration
export { declarations }
export import M;export module M; marks an interface unit of the named module M. In contrast, module M; starts an implementation unit. Marking the interface alone does not export every declaration it contains.
export int f(); exports a function declaration, while export { ... } groups exported declarations without creating a new scope. Their names can be found by name lookup in a translation unit importing the module. Export declarations must inhabit namespace scope within a module interface unit; they cannot appear in an unnamed namespace or a private module fragment. export static int x; is invalid because the name has internal linkage.
export import M; re-exports an import: it makes the exported interface of M available to importers of the current module as well. Plain import M; does not provide that re-export. In the module unit's declaration sequence, imports, including re-exported imports, must precede all other declarations in that sequence. If the unit has a private module fragment, the rule applies separately there: imports must precede all other declarations within the fragment. Thus a plain import at the start of the private module fragment can follow declarations in the preceding sequence.
The example requires two separate files. answer_value is exported, so main.cpp can call it after import answer;. The eel.is source is an evolving working draft, not a frozen C++23 edition; the example requires local verification of module support.
Examples
// answer.cppm
export module answer;
export constexpr int answer_value() {
return 42;
}
// main.cpp
#include <cstdio>
import answer;
int main() {
std::printf("%d\n", answer_value());
}
Result
42
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.