Whenever I use the standard library, I immediately think of headers like <vector>, <algorithm>, and <tuple>. These are all generally useful libraries that greatly facilitate writing complex programs. Sure, there are some areas that are notably lacking, such as robust Unicode support and XML, but at least there is a standards set of libraries to use for the basics.
The paragraph that caused my confusion is 17.6.1.3.2 [compliance]:
A freestanding implementation has an implementation-defined set of headers. This set shall include at least the headers shown in Table 16.
| Subclause | Header(s) | |
|---|---|---|
| <ciso646> | ||
| 18.2 | Types | <cstddef> |
| 18.3 | Implementation properties | <cfloat> <limits> <climits> |
| 18.4 | Integer types | <cstdint> |
| 18.5 | Start and termination | <cstdlib> |
| 18.6 | Dynamic memory management | <new> |
| 18.7 | Type identification | <typeinfo> |
| 18.8 | Exception handling | <exception> |
| 18.9 | Initializer lists | <initializer_list> |
| 18.10 | Other runtime support | <cstdalign> <cstdarg> <cstdbool> |
| 20.9 | Type traits | <type_traits> |
| 29 | Atomics | <atomic> |
This list is missing many of the headers that I take for granted. In order to understand what is intended by "freestanding implementation" you have to go to section 1.4.7 [intro.compliance].
Note that this list of libraries is a minimum. The implementation is permitted to implement any additional standard library headers, or other libraries that might be useful on the target.
Why would a freestanding implementation not implement the rest of the standard library? Certain libraries might not make sense on a target. If the processor only has 4 KiB of RAM, then there likely is not enough horsepower or memory to run or use <regex>, so it wouldn't make sense to have an implementation of that library. On the other hand, an freestanding implementation with 512 MiB of RAM would be more likely to have <regex>.
Even some of the more common libraries, such as <vector> can cause issues with the less capable targets. With only 4 KiB of RAM you start to really worry about memory fragmentation. Since std::vector can fragment memory when reallocation happens, some C++ implementations might not support it, and others might support it, trusting that the programmer is smart enough to use it intelligently.
Embedded systems, and other freestanding C++ implementations often have restrictions that make large sections of the standard library unsuitable for use. In these cases the programmer may have to implement their own libraries that are more suited for the target.
Two kinds of implementations are defined: a hosted implementation and a freestanding implementation. For a hosted implementation, this International Standard defines the set of available libraries. 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.Basically, a freestanding implementation is any C++ target that is not hosted in an operating system. A hosted implementation would be the standard Linux, OS X, Windows, QNX, etc., targets that many compilers can target. A freestanding implementation compiles for bare metal with no platform between the compiled code and the generated executable. Freestanding implementations tend to be embedded systems, though some hosted implementations could be embedded systems, too.
Note that this list of libraries is a minimum. The implementation is permitted to implement any additional standard library headers, or other libraries that might be useful on the target.
Why would a freestanding implementation not implement the rest of the standard library? Certain libraries might not make sense on a target. If the processor only has 4 KiB of RAM, then there likely is not enough horsepower or memory to run or use <regex>, so it wouldn't make sense to have an implementation of that library. On the other hand, an freestanding implementation with 512 MiB of RAM would be more likely to have <regex>.
Even some of the more common libraries, such as <vector> can cause issues with the less capable targets. With only 4 KiB of RAM you start to really worry about memory fragmentation. Since std::vector can fragment memory when reallocation happens, some C++ implementations might not support it, and others might support it, trusting that the programmer is smart enough to use it intelligently.
Embedded systems, and other freestanding C++ implementations often have restrictions that make large sections of the standard library unsuitable for use. In these cases the programmer may have to implement their own libraries that are more suited for the target.
No comments:
Post a Comment