2 ms·
Using anything other than C makes one's code unusable as a general purpose library due to the complexity of the binary interfaces. Writing C++ ensures the code
by matheusmoreira 7y ago
Using anything other than C makes one's code unusable as a general purpose library due to the complexity of the binary interfaces. Writing C++ ensures the code won't be touched by anything but more C++ code. A Python script can load a C library shared object, resolve a symbol to a function pointer and call it. I don't think I'll ever see Python load a C++ library shared object, obtain a pointer to a C++ object and call methods on it using the C++ ABI and handle the C++ exceptions it may throw.
The only way to interoperate is to sacrifice all the benefits of C++ and adopt a C interface. Rust has this feature as well. I like how the creator of Zig put it: if it doesn't speak the C ABI, someone's gonna rewrite it in C.
https://youtu.be/Gv2I7qTux7g?t=2m https://youtu.be/Gv2I7qTux7g?t=2m
- bluGill 7y agoIn practice the C++ ABI issues are only on Microsoft Windows from what I can tell. Everything else seems to have long ago standardized on the itaniam C++ ABI, with one c++ standard library for everything in the system. Upgrades do happen, but they are major system updates where you are required to rebuild everything (generally by installing packages) so it all works. It is possible to violate those, either with a different ABI, or a different incompatible library of course, but in practice nobody does. Microsoft has their own ABI (which is annoying, but otherwise there is nothing wrong with it), but they made the "mistake" of tieing it and the standard library to the compiler not the system thus ensuring you will generally have more than one ABI to worry about unless you are careful. They do this because they have a rule that if it ever ran on a Microsoft OS it will still run (I think they have dropped some DOS and Windows 16 support, but otherwise they are famously bug compatible when bugs are exploited). I understand why Microsoft made these decisions, but for developers they are a problem.
- matheusmoreira 7y agoEven if it is stable, it's still far too complex. The compilers generate so much machinery it's not realistic to expect interoperability with foreign code.
- bluGill 7y agoIt works pretty well on unixish systems. It is complex of course, but that is on the compiler writers not the developers.
- chrchang523 7y agoPython has had decent C++ interoperability for several years (see https://cython.readthedocs.io/en/latest/src/userguide/wrapping_CPlusPlus.html https://cython.readthedocs.io/en/latest/src/userguide/wrappi... ). Though, yes, C has better support.