34 ms·
> > 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 fea
by 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.