3 votes

Zig has function colors

2 comments

  1. teaearlgraycold
    Link
    I only read the first third or so. But the sense I’m getting is that I don’t want to write Zig code if I can use Rust. Reading that core language semantics (suspend and resume) need to exist in...

    I only read the first third or so. But the sense I’m getting is that I don’t want to write Zig code if I can use Rust. Reading that core language semantics (suspend and resume) need to exist in pairs but there’s no compile-time enforcement of that sounds exactly like malloc/free. And being able to cast an async function to sync without any “unsafe”-like alerts to the reader is frightening.

    3 votes
  2. skybrian
    Link
    I found the article long and confusing and didn't read it carefully. But my understanding is that Zig lets you make functions that use regular C calling conventions, but it also has its own...

    I found the article long and confusing and didn't read it carefully. But my understanding is that Zig lets you make functions that use regular C calling conventions, but it also has its own calling conventions that are only used when Zig code is compiled together with other Zig code. Also, if you want to use dynamic linking, you need to use C API's.

    In particular, the fancy async stuff is all Zig-specific and it comes down to code being compiled either way, as needed by the caller. This is much like using monomorphism to compile code that uses generics. It's write once, compile both ways. Hopefully, the library that you're calling into is written with that in mind and tested both ways?

    How do you do async from C? You use C callbacks. There is no magic; the C function either blocks or it returns.

    2 votes