Date: Fri, 8 May 2026 17:34:49 +0200
Here is my understanding of the current situation:
The set of importable headers is implementation-defined, and can
potentially include all headers.
The compiler may, at its discretion, turn all #includes of importable
headers into imports. Which, again, is potentially all headers.
Imported headers, unlike #included headers, do not have access to the
preprocessor state of the importing translation unit.
Therefore any usage of #defines to pass data into a header is no longer
standard-conforming, even if #include is used instead of import.
Is this correct? Because if so, this breaks a lot of existing code.
For example:
The widely used stb family of single header libraries
(https://github.com/nothings/stb) all require a STB_*_IMPLEMENTATION
symbol to be #defined in exactly one translation unit that #includes the
header. The same idiom is widely used in other single-header libraries
such as DocTest (https://github.com/doctest/doctest).
Boost.Test (https://www.boost.org/library/latest/test/) uses a variation
of the above idiom, requiring BOOST_TEST_MODULE to be #defined in
exactly one translation unit before #including the relevant header.
Unlike the above case, the value of BOOST_TEST_MODULE is also used to
configure Boost.Test.
Another idiom, used by SDL (https://www.libsdl.org/) for example, uses a
variant of the X macro technique (https://en.wikipedia.org/wiki/X_macro)
where the same header file is #included multiple times in the same
translation unit, each time with different definitions for the macros
that the header file calls.
The set of importable headers is implementation-defined, and can
potentially include all headers.
The compiler may, at its discretion, turn all #includes of importable
headers into imports. Which, again, is potentially all headers.
Imported headers, unlike #included headers, do not have access to the
preprocessor state of the importing translation unit.
Therefore any usage of #defines to pass data into a header is no longer
standard-conforming, even if #include is used instead of import.
Is this correct? Because if so, this breaks a lot of existing code.
For example:
The widely used stb family of single header libraries
(https://github.com/nothings/stb) all require a STB_*_IMPLEMENTATION
symbol to be #defined in exactly one translation unit that #includes the
header. The same idiom is widely used in other single-header libraries
such as DocTest (https://github.com/doctest/doctest).
Boost.Test (https://www.boost.org/library/latest/test/) uses a variation
of the above idiom, requiring BOOST_TEST_MODULE to be #defined in
exactly one translation unit before #including the relevant header.
Unlike the above case, the value of BOOST_TEST_MODULE is also used to
configure Boost.Test.
Another idiom, used by SDL (https://www.libsdl.org/) for example, uses a
variant of the X macro technique (https://en.wikipedia.org/wiki/X_macro)
where the same header file is #included multiple times in the same
translation unit, each time with different definitions for the macros
that the header file calls.
-- Rainer Deyke - rainerd_at_[hidden]
Received on 2026-05-08 15:35:02
