What are the features that I can use in c++ freestanding environment? I am developing a little kernel (for my own pleasure) and I know that I can't use the whole stdlib library, but what else ? when I tried to use the new and delete operators it compiled without troubles but the linker said
undefined reference to `operator new[](unsigned long)
undefined reference to `operator delete[](void*)'
I link with -lgcc
and -lsupc++
options. I know that exception handling is disable in freestanding but I am a little bit surprised that new and delete are also. So what can I use and what can I not?
A freestanding implementation is a C translation and execution environment with nearly full language support but essentially no support for the standard library's runtime components–an environment not uncommon among low-end embedded systems.
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.
C++20/C++2a brings new features to the synchronization library, including atomic smart pointers, latchers, and barriers. We review its all-new coroutines (a major concept found in other leading programming languages that simplifies writing code for parallel execution).
C++20 is a version of the ISO/IEC 14882 standard for the C++ programming language. C++20 replaced the prior version of the C++ standard, called C++17. The standard was technically finalized by WG21 at the meeting in Prague in February 2020, approved on 4 September 2020, and published in December 2020.
What are the features that I can use in c++ freestanding environment?
Much of freestanding implementations is implementation defined:
[intro.compliance] ... A freestanding implementation is one in which execution may take place without the benefit of an operating system, and has an implementation-defined set of libraries that includes certain language-support libraries
[intro.multithread] ... Under a freestanding implementation, it is implementation-defined whether a program can have more than one thread of execution.
[basic.start.main] It is implementation-defined whether a program in a freestanding environment is required to define a main function. [ Note: In a freestanding environment, 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. — end note ]
[using.headers] C ++ headers for freestanding implementations
<ciso646> <cstddef> <cfloat> <limits> <climits> <cstdint> <cstdlib> <new> <typeinfo> <exception> <initializer_list> <cstdalign> <cstdarg> <cstdbool> <atomic>
[compliance] The supplied version of the header
<cstdlib>
shall declare at least the functions abort, atexit, at_quick_- exit, exit, and quick_exit (18.5). The other headers listed in this table shall meet the same requirements as for a hosted implementation.
Note that malloc
/free
are not listed in the required functions of <cstdlib>
.
As far as your linker error is concerned, neither freestanding, nor hosted implementation is required to provide those overloads:
[replacement.functions] A C ++ program may provide the definition for any of twelve dynamic memory allocation function signatures declared in header
<new>
In practice, since a free standing environment cannot depend on an OS, and malloc
is usually implemented using features provided by an OS, it is unlikely to have free store memory management features in a freestanding environment. Conversely, a hosted environment requires free store memory management to implement the features of the standard library.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With