3 ms·
> They are incredibly similar, though. Not even close. C++ is a vastly more complex language with a very different philosophy from that of C. You might argue
by MaxBarraclough 5y ago
> They are incredibly similar, though.
Not even close. C++ is a vastly more complex language with a very different philosophy from that of C.
You might argue that C can very roughly be treated as a subset of C++, but this really is a very rough approximation. Which is to say, really, that it's wrong.
> And they inter-link
It's generally very easy to call C code from C++ code, yes. It is not easy to call C++ code from C.
- pjc50 5y ago> C can very roughly be treated as a subset of C++ Well, 99% of the time this holds, and you can generally use the same tooling in different modes for both. And they share a preprocessor. > It's generally very easy to call C code from C++ code, yes. It is not easy to call C++ code from C. Significantly easier than almost any other pair of languages, though. Especially if you take a little care on the C++ side (extern "C") or use COM or similar. Again, C is more compatible with C++ than python 2 is with python 3. But not the other way round.
- seba_dos1 5y ago"99% of the time" may be stretching it a bit when you have to prevent yourself from using modern and useful C features in order to get a C++ compiler to accept your codebase.
- MaxBarraclough 5y ago> > It is not easy to call C++ code from C. > Significantly easier than almost any other pair of languages, though. I wouldn't say so. If you're using the features of C++ then you'd need to manually wrap it all to expose a C API. Accessing C code from C++, Ada, Rust, Zig, Java, Python, C#, or just about any other language, would be easier than manually wrapping C++ to expose a C API. (The LLVM compiler, written in C++, does this. It exposes a subset of its API as a C API. I get the impression it's no small task, or they'd expose the full LLVM library that way.) > Especially if you take a little care on the C++ side (extern "C") or use COM or similar. Agreed, but going the extern "C" route implies you're using C++ as a better C, rather than making full use of C++. I have to admit I don't know much about working with COM. It's vaguely like GObject, right? I imagine it must take quite a bit of work to expose a C++ API that way.