There's actually multiple standard libraries for embedded applications and a lot of the standard library from C++11 and on was designed with embedded in mind in particular.
And with each std release the particularly nasty parts of std get decoupled from the rest of the library. So it's at the point nowadays where you can use all the commonly used parts of std in an embedded environment. So that means you get all your containers, iterators, ranges, views, smart/RAII pointers, smart/RAII concurrency primitives. And on the bleeding edge you can even get coroutines, generators, green threads, etc in an embedded environment with "pay for what you use" overhead. Intel has been pushing embedded stdlib really hard over the past few years and both they and Nvidia have been spearheading the senders and receivers concurrency effort. Intel uses S&R internally for handling concurrency in their embedded environments internal to the CPU and elsewhere in their hardware.
(Also fun side note but STL doesn't "really" stand for "standard template library". Some projects have retroactively decided to refer to it as that but that's not where the term STL comes from. STL stands for the Adobe "Software Technology Lab" where Stepanov's STL project was formed and the project prior to being proposed to committee was named after the lab.)
AFAIK Stepanov only joined Adobe much later. I think he was at HP during the development of the STL, but moved to SGI shortly after (possibly during standardization).
The other apocryphal derivation of STL I have heard is "STepanov and Lee".
AFAIK He started work on the STL at HP and then SGI based on his and Musser's work on Generic Programming but it didn't get the name STL until he was at the STL.
This of course coming from Sean Parent who was and afaik still is quite close with Stepanov. Sean Parent of course being famous in his own right but also being notable for bringing Stepanov to Adobe and being the one to push for Stepanov to propose the STL to WG21 (the C++ ISO Std committee).
freestanding requires almost all std library. Please note that -fno-rtti and -fno-exceptions are non-conformant, c++ standard does not permit either.
Also, such std:: members as initializer_list, type_info etc are directly baked into compiler and stuff in header must exactly match internals — making std library a part of compiler implementation
have you actually read the page you linked to? None of the standard containers is there, nor <iostream> or <algorithm>. <string> is there but marked as partial.
If anything, I would expect more headers like <algorithm>, <span>, <array> etc to be there as they mostly do not require any heap allocation nor exceptions for most of their functionality. And in fact they are available with GCC.
The only bit I'm surprised is that coroutine is there, as they normally allocate, but I guess it has full support for custom allocators, so it can be made to work on freestanding.
> Please note that -fno-rtti and -fno-exceptions are non-conformant, c++ standard does not permit either.
I did not know that.
My understanding was that C does not require standard library functions to be present in freestanding. The Linux kernel famously does not build in freestanding mode, since then GCC can't reason about the standard library functions which they want. This means that they need to implement stuff like memcpy and pass -fno-builtin.
Does that mean that freestanding C++ requires the C++ standard library, but not the C standard library? How does that work?
Honestly? No idea how the committee is thinking. When, say, gamedev people write proposal, ask for a feature, explain it is important and something they depend on and so on, it gets shot down on technicality. Then they turn around and produce some insane feature that, like, rips everything east to west (like modules), and suddenly voting goes positive.
The "abstract machine" C++ assumes in the standard is itself a deeply puzzling construct. Luckily, compiler authors seem much more pragmatic and reasonable, I do not fear -fno-exceptions dissapearing suddenly, or code that accesses mmapped data becoming invalid because it didn't use start_lifetime_as
One of required headers in freestanding, <cstdlib>, is labelled "C standard library", but it is not <stdlib.h>
Something similar with other <csomething> headers.
This kinda implies C library is required, if I read it correctly, but maybe someone else can correct me:
https://eel.is/c++draft/library.c
> The ISO C standard defines (in clause 4) two classes of conforming
implementation. A "conforming hosted implementation" supports the whole
standard including all the library facilities; a "conforming
freestanding implementation" is only required to provide certain library
facilities: those in '<float.h>', '<limits.h>', '<stdarg.h>', and
'<stddef.h>'; since AMD1, also those in '<iso646.h>'; since C99, also
those in '<stdbool.h>' and '<stdint.h>'; and since C11, also those in
'<stdalign.h>' and '<stdnoreturn.h>'. In addition, complex types, added
in C99, are not required for freestanding implementations.
> The standard also defines two environments for programs, a
"freestanding environment", required of all implementations and which
may not have library facilities beyond those required of freestanding
implementations, where the handling of program startup and termination
are implementation-defined; and a "hosted environment", which is not
required, in which all the library facilities are provided and startup
is through a function 'int main (void)' or 'int main (int, char *[])'.
An OS kernel is an example of a program running in a freestanding
environment; a program using the facilities of an operating system is an
example of a program running in a hosted environment.
> GCC aims towards being usable as a conforming freestanding
implementation, or as the compiler for a conforming hosted
implementation. By default, it acts as the compiler for a hosted
implementation, defining '__STDC_HOSTED__' as '1' and presuming that
when the names of ISO C functions are used, they have the semantics
defined in the standard. To make it act as a conforming freestanding
implementation for a freestanding environment, use the option
'-ffreestanding'; it then defines '__STDC_HOSTED__' to '0' and does not
make assumptions about the meanings of function names from the standard
library, with exceptions noted below. To build an OS kernel, you may
well still need to make your own arrangements for linking and startup.
*Note Options Controlling C Dialect: C Dialect Options.
> GCC does not provide the library facilities required only of hosted
implementations, nor yet all the facilities required by C99 of
freestanding implementations on all platforms. To use the facilities of
a hosted environment, you need to find them elsewhere (for example, in
the GNU C library). *Note Standard Libraries: Standard Libraries.
> Most of the compiler support routines used by GCC are present in
'libgcc', but there are a few exceptions. GCC requires the freestanding
environment provide 'memcpy', 'memmove', 'memset' and 'memcmp'.
Finally, if '__builtin_trap' is used, and the target does not implement
the 'trap' pattern, then GCC emits a call to 'abort'.
So the last paragraph means that my remark about the Linux kernel might be wrong.
So the required headers are all about basic constants for types, the types themselves (bool), and basic language features like stdarg, iso646 or stdalign. Sounds sensible to me. Not sure what C++ does with that.
This also actually matches the links provided by you. In https://eel.is/c++draft/cstdlib.syn you see that not all declarations are actually marked for freestanding implementations.
Citation needed. This is common for embedded application, since why would anyone program a STL for that?