4 ms·
So Rust's C interop is limited to implementing the platform calling conventions? It's nice that Rust can do that but this is NOT better, it's a significant limi
by ridiculous_fish 8y ago
So Rust's C interop is limited to implementing the platform calling conventions? It's nice that Rust can do that but this is NOT better, it's a significant limitation. A deliberate, defensible one, but a limitation none-the-less.
Here's a real example. If you write C, you'll probably make a system call, and then check errno. You might also write to errno, e.g. save and restore.
errno is implemented differently on every platform, but a C program can include errno.h, and use it portably. C++ can do the same thing: include errno.h and you're done.
But Rust can't read the C header, so it must literally special-case every OS [1].
errno is just one thing, but there's a long tail: different platforms have different types and size and function names and signatures, especially the ancient system-y stuff.
"Rust is better than C++ at C interop" is an absurd take. The point of Rust is to displace this stuff, not be the best at integrating with it.
1: https://github.com/rust-lang/rust/blob/7cb3ee453b829a513749eb49e6cbe7fe4da527b1/src/libstd/sys/unix/os.rs#L28 https://github.com/rust-lang/rust/blob/7cb3ee453b829a513749e...
- nicoburns 8y ago> errno is implemented differently on every platform, > But Rust can't read the C header, so it must literally special-case every OS [1]. That's a bit of an odd point. You're saying that the C standard library implementation of errno is different on each platform, but abstracted in the standard library so that C programs can just import it and run a portable function. ...and then you complain that Rust does the same...