There are two kinds of implementations defined by the C++ standard: hosted and freestanding implementations. For hosted implementations, the set of standard library headers required by the C++ standard is much larger than for freestanding ones. In a freestanding implementation, execution may happen without an operating system.
The kind of the implementation is implementation-defined. The predefined macro __STDC_HOSTED__ is expanded to 1 for hosted implementations and 0 for freestanding implementations.(since C++11)
Requirements on
multi-threaded executions and data races
freestandinghostedUnder a freestanding implementation, it is implementation-defined whether a program can have more than one
. Under a hosted implementation, a C++ program can have more than one
running concurrently. (since C++11)Requirements on the
function
freestandinghostedIn a freestanding implementation, it is implementation-defined whether a program is required to define a
function. Start-up and termination is implementation-defined; start-up contains the execution of
for objects of
with static storage duration; termination contains the execution of
for objects with static
. In a hosted implementation, a program must contain a global function called
. Executing a program starts a main
in which the main function is invoked, and in which variables of static
might be initialized and destroyed. Requirements on
A freestanding implementation has an implementation-defined set of headers. This set includes at least the headers in the following table.
For partially freestanding headers, freestanding implementations only needs to provide part of the entities in the corresponding synopsis:
If an entity is commented // freestanding, it is guaranteed to be provided.
If an entity (function or function template) is commented // freestanding-deleted, it is guaranteed to be either provided or deleted.
(since C++26)If an entity is declared in a header whose synopsis begins with allfreestanding or // mostly freestanding, it is guaranteed to be provided if the entity itself is not commented.
Headers required for a freestanding implementation
Library Component Headers Freestanding
Common definitions
All C standard library
Partial Implementation properties
(since C++11)
(since C++20)All Integer types
(since C++11)All Dynamic memory management
All Type identification
All Source location
(since C++20)All Exception handling
All Initializer lists
(since C++11)All Comparisons
(since C++20)All Coroutines support
(since C++20)All Other runtime support
All Debugging support
(since C++26)All
(since C++20)All
Error numbers
(since C++26)Partial System error support
(since C++26)Partial
Memory
(since C++23)Partial
Type traits
(since C++11)All Compile-time rational arithmetic
(since C++23)All
Utility components
(since C++23)All Tuples
(since C++23)All Function objects
(since C++20)Partial Primitive numeric conversions
(since C++26)Partial Bit manipulation
(since C++20)All
String classes
(since C++26)Partial Null-terminated
sequence utilities
(since C++26)Partial
Null-terminated
sequence utilities
(since C++26)Partial
(since C++23)Partial
(since C++23)Partial
Mathematical functions
for floating-point types
(since C++26)Partial Random number generation
(since C++26)Partial
Atomics
(since C++11) All
(since C++26)Partial Deprecated headers
(until C++20)
(since C++11)(until C++20)
(since C++11)(until C++20)All
Support for always lock-free integral atomic types and presence of type aliases
and
std::atomic_unsigned_lock_free
are implementation-defined in a freestanding implementation.(since C++20)
Notes
Some compiler vendors may not fully support freestanding implementation. For example, GCC libstdc++ has had implementation and build issues before version 13, while LLVM libcxx and MSVC STL do not support freestanding.
In C++23, many features are made freestanding with partial headers. However, it is still up for discussion in WG21 whether some headers will be made freestanding in the future standards. Regardless, containers like
,
,
, and
will never be freestanding due to their dependencies on exceptions and heap.
GCC 13 provides more headers, such as
,
,
, and
, for freestanding, although these headers may not be portable or provide the same capabilities as a hosted implementation. It is better to avoid using them in a freestanding environment, even if the toolchain provides them.
macro ValueStdFeature
__cpp_lib_freestanding_feature_test_macros
(C++26)freestanding feature test macros
__cpp_lib_freestanding_algorithm
(C++26)freestanding
(C++26)more freestanding facilities in
(C++26)freestanding
__cpp_lib_freestanding_char_traits
(C++26)freestanding
__cpp_lib_freestanding_charconv
(C++26)freestanding
__cpp_lib_freestanding_cstdlib
(C++26)freestanding
__cpp_lib_freestanding_cstring
(C++26)freestanding
(C++26)freestanding
(C++26)freestanding
__cpp_lib_freestanding_execution
(C++26)freestanding
__cpp_lib_freestanding_expected
(C++26)freestanding
__cpp_lib_freestanding_functional
(C++26)freestanding
__cpp_lib_freestanding_iterator
(C++26)freestanding
(C++26)freestanding
(C++26)freestanding
(C++26)more freestanding facilities in
__cpp_lib_freestanding_numeric
(C++26)freestanding
(C++26)more freestanding facilities in
__cpp_lib_freestanding_optional
(C++26)freestanding
(C++26)freestanding
(C++26)freestanding
(C++26)freestanding
__cpp_lib_freestanding_string_view
(C++26)freestanding
(C++26)freestanding
__cpp_lib_freestanding_utility
(C++26)freestanding
__cpp_lib_freestanding_variant
(C++26)freestanding
References
C++23 standard (ISO/IEC 14882:2024):
4.1 Implementation compliance [intro.compliance] (p: 10)
6.9.2 Multi-threaded executions and data races [intro.multithread] (p: 84)
6.9.3.1 main function [basic.start.main] (p: 89)
16.4.2.5 Freestanding implementations [compliance] (p: 483)
C++20 standard (ISO/IEC 14882:2020):
4.1 Implementation compliance [intro.compliance] (p: 7)
6.9.2 Multi-threaded executions and data races [intro.multithread] (p: 77)
6.9.3.1 main function [basic.start.main] (p: 82)
16.5.1.3 Freestanding implementations [compliance] (p: 470)
C++17 standard (ISO/IEC 14882:2017):
4.1 Implementation compliance [intro.compliance] (p: 5)
4.7 Multi-threaded executions and data races [intro.multithread] (p: 15)
6.6.1 main function [basic.start.main] (p: 66)
20.5.1.3 Freestanding implementations [compliance] (p: 458)
C++14 standard (ISO/IEC 14882:2014):
1.4 Implementation compliance [intro.compliance] (p: 5)
1.10 Multi-threaded executions and data races [intro.multithread] (p: 11)
3.6.1 Main function [basic.start.main] (p: 62)
17.6.1.3 Freestanding implementations [compliance] (p: 441)
C++11 standard (ISO/IEC 14882:2011):
1.4 Implementation compliance [intro.compliance] (p: 5)
1.10 Multi-threaded executions and data races [intro.multithread] (p: 11)
3.6.1 Main function [basic.start.main] (p: 58)
17.6.1.3 Freestanding implementations [compliance] (p: 408)
C++03 standard (ISO/IEC 14882:2003):
1.4 Implementation compliance [intro.compliance] (p: 3)
3.6.1 Main function [basic.start.main] (p: 43)
17.4.1.3 Freestanding implementations [lib.compliance] (p: 326)
Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior
C++98 an implementation did not need
to document whether it is hosted made the implementation kind implementation-
defined (thus requires a documentation)
(
) C++20
is freestanding, but
uses
which was not made
being
partially freestanding See also