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 macro __STDC_HOSTED__ is predefined to 1 for hosted implementations and 0 for freestanding implementations.
freestanding |
hosted
|
Under a freestanding implementation, it is implementation-defined whether a program can have more than one thread of execution.
|
Under a hosted implementation, a C++ program can have more than one thread running concurrently.
|
|
(since C++11) |
[edit] Requirements on the main function
freestanding |
hosted
|
In a freestanding implementation, it is implementation-defined whether a program is required to define a main function. Start-up and termination is implementation-defined; start-up contains the execution of constructors for objects of namespace scope with static storage duration; termination contains the execution of destructors for objects with static storage duration.
|
In a hosted implementation, a program must contain a global function called main. Executing a program starts a main thread of execution in which the main function is invoked, and in which variables of static storage duration might be initialized and destroyed.
|
A freestanding implementation has an implementation-defined set of headers. This set includes at least the headers in the following table:
- ↑ The supplied version of the header
<cstdlib>
shall declare at least the functions std::abort, std::atexit, std::exit, std::at_quick_exit and std::quick_exit (since C++11).
- ↑ Support for always lock-free integral atomic types and presence of type aliases std::atomic_signed_lock_free and std::atomic_unsigned_lock_free are implementation-defined in a freestanding implementation. (since C++20)
[edit] References
- 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)
[edit] See also