3 ms·
RAII is one of the best things about C++. It makes cleanup much simpler than what you need to do without being able to bind cleanup code to scopes. You avoid th
by adrianN 5y ago
RAII is one of the best things about C++. It makes cleanup much simpler than what you need to do without being able to bind cleanup code to scopes. You avoid the kind of complexity that can lead to "goto fail" style problems.
- bsder 5y agoIf you want RAII, then use C++--no one is stopping you. A lot of embedded developers STRONGLY disagree with you. There is a reason why embedded developers tend to turn off a whole bunch of C++ features. Note all the: "No RTTI. No templates. No exceptions." flags that embedded folks always engage. Now that VSCode is getting actual support for embedded (see all the work the Rust Embedded guys did, for example) as well as official ARM support (Eclipse Theia), various languages can be used for development. Thanks to this, people no longer need to force things because "If it's not in the C toolchain, nobody will support it." People don't need to torture C anymore to use their favorite language feature on their hardware of choice.
- adrianN 5y agoThanks, I did safety critical embedded development for while, in C++. We did turn off a bunch of features of course. We never heap-alloced for example. But destructors were used extensively to make sure that important actions happened during error conditions. We were lucky to be able to use C++ because we had a compiler for our target platform. Not every target has a C++ compiler, so I think adding something as useful as scope-bound cleanup to C makes perfect sense.