3 ms·
Yeah, I mean, I know I'm asking for a lot. No other language comes close to rust as far as C interop, except C++. And rust is actually better at C interop than
by jeff-davis 5y ago
Yeah, I mean, I know I'm asking for a lot. No other language comes close to rust as far as C interop, except C++.
And rust is actually better at C interop than C++ in some important ways!
* Rust doesn't mess with struct definitions if they are declared #[repr(C)]. No extra vtable pointers. That means you can pass a struct back and forth between C and rust, and in the rust code you can do dynamic dispatch on that same C struct (no copying/conversion). That's amazing!
* Rust defines Option<&Foo> in a #[repr(C)] struct to be a plain pointer, where NULL means None. That means you can get type safety in rust working with nullable pointers you get from C, to make sure that your rust code checks for None. Again, no conversion or copying, you get this with ordinary nullable pointers coming from C.
- nynx 5y agoBack when I was working on wasm runtimes, I ran into the issue of unwinding an exception through generated code. I had to do something reminiscent of what I mentioned above.