Namespaces
Variants
Views
Actions

cpp/freestanding

From cppreference.com
< cpp
Revision as of 02:11, 10 September 2018 by 37.113.176.110 (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

There are two kinds of implementations defined by the C++ standard: hosted and freestanding implementations. For hosted implementations the set of available libraries required by the C++ standard is much larger than for freestanding ones. In a freestanding implementation execution may happen without an operating system.

A freestanding implementation has an implementation-defined set of headers. This set includes at least the headers in the following table:

Headers required for a freestanding implementation
<ciso646>
Types <cstddef>
Implementation properties <cfloat> <limits> <climits>
Integer types <cstdint>
Start and termination <cstdlib>
Dynamic memory management <new>
Type identification <typeinfo>
Exception handling <exception>
Initializer lists <initializer_list>
Other runtime support <cstdarg>
Type traits <type_traits>
Atomics <atomic>
Deprecated headers <cstdalign> <cstdbool>

The following are the differences between freestanding and hosted 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.
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.

References