3 ms·
Modern 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 exceptio
by kevin_thibedeau 2y ago
Modern 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.