logoalt Hacker News

112233last Monday at 2:06 PM2 repliesview on HN

gladly! Since deep-linking draft pdf from phone is hard, here is the next best thing: https://en.cppreference.com/w/cpp/freestanding.html

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


Replies

gpderettalast Monday at 5:18 PM

> freestanding requires almost all std library.

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.

1718627440last Monday at 2:43 PM

> 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?

show 1 reply