4 ms·
That’s not true. C++ code can be called from foreign languages just as easily as C, you just have to provide C-like interface and mark it as extern “C”.
by xyzzyz 5y ago
That’s not true. C++ code can be called from foreign languages just as easily as C, you just have to provide C-like interface and mark it as extern “C”.
- qsort 5y agoSure, but that means I have to provide the interface myself. One of the main advantages of C++ over C is that you don't have to pass around pointers to structs, so you're stuck between using C++ as basically C, or duplicating every object the API needs to expose. Obviously you can make it work, and it probably makes a lot of sense for larger libraries where the advantages of working with C++ really pull their weight, but regardless, FFI is still one of the (admittedly fewer and fewer) niches where C shines.
- xyzzyz 5y ago> you're stuck between using C++ as basically C, or duplicating every object the API needs to expose Yes, you need to provide the C-like interface on the API boundary, but internally you can just use normal C++ for everything else. Sure, that C-like interface will not be as nice and comfortable as it would have been with C++ interface, but then again, neither it would be if you used C instead of C++. > FFI is still one of the (admittedly fewer and fewer) niches where C shines. No, it’s C linkage that shines, and C++ can use C linkage just fine.
- deleted 5y ago[deleted]
- lelanthran 5y ago> That’s not true. C++ code can be called from foreign languages just as easily as C, you just have to provide C-like interface and mark it as extern “C”. And ensure that you catch every exception and turn it into an error code?