6 ms·
You're right about the massive amounts of C/C++ code out there. I'd disagree that the integration is harder than with C++, though. Calling Rust from C and vice
by omn1 6y ago
You're right about the massive amounts of C/C++ code out there.
I'd disagree that the integration is harder than with C++, though.
Calling Rust from C and vice versa is fairly straightforward and there are automatic code generators for doing so. Things just get wrapped into an `unsafe` block and that gives you the same guarantees you'd have with C++ (none, basically). From there you can start to gradually rewrite critical parts in safe Rust and profit from the cargo ecosystem along the way.
In that sense there's even an advantage for Rust over C++ in my book.
- est31 6y agoIntegrating with C is easier than with C++ but it still needs those safe wrappers. With C++ you can use stuff directly, and maybe sometimes have to convert between say C and C++ strings. Integrating with C++ is much harder, especially if some C++ features are used. What if you have to inherit a class to do something? What if there is a generic function that you need to invoke? Even tasks as simple as catching exceptions are difficult. Things have improved with dtolnay's cxx thankfully.
- ncmncm 6y agoCalling C++ libraries from Rust is in general impossible. The more useful the library is, the less likely it is that Rust can call it. As the languages evolve, that will sharpen. There is no "C/C++" code. Using the expression mainly generates confusion, most usually in the person saying it.