4 ms·
So why not use C++? Since it's a superset of C, why not just use C++ to program C-style code, using only the C++ features you want? C++ is a multi-paradigm lan
by KeytarHero 12y ago
So why not use C++?
Since it's a superset of C, why not just use C++ to program C-style code, using only the C++ features you want? C++ is a multi-paradigm language; you don't have to write object-oriented code if you don't want.
- byuu 12y agoCode portability is a big one. People write C compilers in a week as a hobby. Now compare to how long it took Clang to fully support all of C++. Now certainly, C++ is on every major platform in broad use. But maybe you are targeting something embedded, or a hobbyist OS. Or maybe you want to write up a quick embedded interpreter for scripting in your application. There's something intrinsically satisfying about minimalism and simplicity. It's also really hard to control the feature-set of C++ you want. The second you start pulling in code libraries, you find yourself needing to use the parts you don't want. Not in your own code directly, but in your interactions with their library code. Catching exceptions, needing RTTI, etc. Symbol exporting is also a really sore point in C++. The symbol names C++ compilers spit out are just terrifying. With a C language, it's trivial to write bindings for other languages like C# and Python. But for what it's worth, I still program almost exclusively in C++.
- KeytarHero 12y agoAren't there C++ compilers that will compile to C code? Doesn't that effectively make C++ just as portable as C?
- byuu 12y ago> Aren't there C++ compilers that will compile to C code? Uh ... no? CFront did that when it was just "C with Classes", but nowadays with C++14? That would be absolutely terrifying.
- cokernel_hacker 12y agoArguably the most versatile compiler in the world is EDG's. One of its features is: "a C-generating back end, which can be used to generate C code for C++ programs" source: https://www.edg.com/index.php?location=c_frontend https://www.edg.com/index.php?location=c_frontend In fact, the Itanium C++ ABI (which has no relation to the architecture) specifically uses valid C identifiers to mangle C++ names to support products like EDG. source: http://mentorembedded.github.io/cxx-abi/abi.html#mangling-type http://mentorembedded.github.io/cxx-abi/abi.html#mangling-ty...