3 ms·
#[no_mangle] extern "C" All due respect to Rust, which is a fantastic language, what this line says is "here is a C function written in Rust". You can of cour
by samatman 6y ago
#[no_mangle] extern "C"
All due respect to Rust, which is a fantastic language, what this line says is "here is a C function written in Rust".
You can of course do the same thing with C++ and with D, allowing all three to check the box for interoperability. And with Rust you get everything Rust offers: so you can write in the `extern "C"` dialect while getting memory-safety guarantees within the library, that's not nothing.
What Zig offers is the ability to write ordinary Zig and call that from C. That's part of what it's designed to do.
This is interoperability by design, rather than by configuration. It's simply a different thing, and considered along this singular dimension, I would assert that it's better.
I didn't, and wouldn't, say that Zig has the potential to replace Rust. I said that about C, and explained why.
- MaulingMonkey 6y ago> What Zig offers is the ability to write ordinary Zig and call that from C. You say that, but Zig appears to suffer from the exact same problem you point out in my Rust code: export https://ziglang.org/documentation/master/#Exporting-a-C-Library https://ziglang.org/documentation/master/#Exporting-a-C-Libr... Perhaps I'm mistaken. How do I directly call Zig's `std.debug.print` from C? Or Timestamp.unixEpoch as defined here? https://ziglang.org/documentation/0.7.1/#Doc-comments https://ziglang.org/documentation/0.7.1/#Doc-comments There's a bunch of rust crates containing macros, binaries, and build scripts that cut down on Rust's boilerplate as well. While there are some rough edges and room for further improvement, I am far happier with Rust's C interop than I am with the C interop of most other languages. Zig might have a touch more polish, but the bit I originally quoted made Rust sound like it was a good order of magnitude worse than Zig at C interop, which I just can't agree with. One of the very first things I did when learning Rust was write a test library and drop it into an existing C++ codebase. I've also experimented heavily with cross compiling it to pretty much anything I can get my hands on. It was a good time, not a bad one.