Re:Linux kernel in-tree Rust support
by zozbot234 on Saturday July 11, 2020 @06:03AM
(#23800886)
Rust integrates easily with C because it's explicitly designed to fall back to the C ABI for external linkage. Whereas writing C++ with any C++-specific features (hence, any "Modern", guidelines-compliant C++ at all) brings its own bespoke ABI into the picture, that's supposed to be stable but really is not and that one can't easily interoperate with from C. That's a huge non-starter in kernel dev.
[ Parent
| on HN ]
Not really, both in Rust and in C++ the C-compatible parts have to be marked explicitly as extern "C". Even the syntax is the same.
C compatibility is marked the same way, but it's not idiomatically used the same way in C++ and Rust. In C++, being C compatible means essentially writing C and for everything else you're expected to rely on the "not really stable" C++ ABI whereas Rust does not even try to give you a stable ABI between stuff that's not part of pretty much the same build. Despite that, you're free to mix C-like and Rustic code in the same crate because the crate is literally the translation unit in Rust.
ABI stability doesn't matter for the kernel since it doesn't have a stable ABI either. You can write a C++ core and C wrappers for C++ classes just fine, the same as what you do in Rust.
I’m a huge Rust fan, but this is a misrepresentation of C++. You can definitely use the vast majority of modern C++ features while also integrating with a C codebase (exotic control flow such as exceptions and coroutines are definitely dangerous, though).