3 ms·
Unlike C++ the C language takes its freestanding mode seriously. In this mode there's no malloc() and so your string type can't exist. But today in freestanding
by tialaramex 4y ago
Unlike C++ the C language takes its freestanding mode seriously. In this mode there's no malloc() and so your string type can't exist. But today in freestanding I can write "ERROR" and get a string literal.
So that would mean either you abolish string literals in freestanding (making C worse) or you have a separate type for these string literals from the type for a expandable string.
Now, Rust pulls off the latter in my view fairly elegantly, but that takes a lot of sophisticated type features in the language including a DeRef and several AsRef implementations. In Rust these are general features open to other types, C could special case them instead, but that's still a lot of engineering for a small feature.
The result is definitely not the elegant language which can be described in a slim book. Maybe it's better anyway, but it's not C.
- saagarjha 4y agoString literals are char arrays, so it seems reasonable to be able to not resize them…
- 323 4y ago> Unlike C++ the C language takes its freestanding mode seriously You can easily implement a stack allocated C++ string: https://forums.4fips.com/viewtopic.php?f=3&t=1075 https://forums.4fips.com/viewtopic.php?f=3&t=1075 You can also wrap a const char* in a string_view which has a length.
- pjmlp 4y agoYou mean the lightly specified section of ISO C standard regarding freestanding use, or the compiler extensions most people ignore aren't part of the standard?