5 ms·
I've tried, but never succeeded in doing that; the complexity eventually seeps in through the cracks. C++'s stdlib contains a lot of convenient features, writi
by codr7 2y ago
I've tried, but never succeeded in doing that; the complexity eventually seeps in through the cracks.
C++'s stdlib contains a lot of convenient features, writing them myself and pretending they aren't there is very difficult.
Disabling exceptions is possible, but will come back to bite you the second you want to pull in external code.
You also lose some of the flexibility of C, unions become more complicated, struct offsets/C style polymorphism isn't even possible if I remember correctly.
I love the idea though :)
- ryandrake 2y ago> C++'s stdlib contains a lot of convenient features, writing them myself and pretending they aren't there is very difficult. I've never understood the motivation behind writing something in C++, but avoiding the standard library. Sure, it's possible to do, but to me, they are inseparable. The basic data types and algorithms provided by the standard library are major reasons to choose the language. They are relatively lightweight and memory-efficient. They are easy to include and link into your program. They are well understood by other C++ programmers--no training required. Throughout my career, I've had to work in places where they had a "No Standard Library" rule, but that just meant they implemented their own, and in all cases the custom library was worse. (Also, none of the companies could articulate a reason for why they chose to re-implement the standard library poorly--It was always blamed on some graybeard who left the company decades ago.) Choosing C++ without the standard library seems like going skiing, but deliberately using only one ski.
- codr7 2y agoThe stdlib makes choices that might not be optimal for everyone. Plenty of code bases also predate it, when I started coding C++ in 1995 most people were still rolling their own.
- kevin_thibedeau 2y agoModern C++ has goodies like consteval that are supremely useful for embedded work. STL and the rest of the stdlib on the other hand depends on heap and exceptions for error reporting which are generally a no go zone for resource constrained targets. You can productively use C++ as C-with-classes (and templates, and namespaces, etc.) without depending on the library. That leaves you no worse off than rolling your own support code in plain C.
- _benton 2y agoCan't you disable exceptions?
- kevin_thibedeau 2y agoYes, but the C++ library becomes inherently broken because there is no error reporting.
- int_19h 2y agoOnly the parts that need to heap-allocate. Which includes most containers, but not e.g. algorithms.
- kevin_thibedeau 2y agoIt's everything that throws, which covers a lot more than STL, including <algorithm>.
- int_19h 2y agoThere are relatively few things that throw, though, unless they allocate. Stuff like e.g. vector::at() is not particularly interesting since it's easy to avoid and doesn't affect other things.
- _benton 2y agoI'm pretty sure Google, LLVM, Firefox etc use the stdlib without exceptions so it's probably possible. You can retrieve the error with errno right?
- kevin_thibedeau 2y agoThey're all YOLOing on the assumption that errors won't happen and doing the system programmer's favorite error handling scheme of calling abort(), then restarting a process. That doesn't fly on an embedded device. Nobody seriously checks errno after every library call without a separate means to indicate a failure happened in the first place.