3 points | by jakeStbu 16 hours ago ago

8 comments

  • an hour ago
    [deleted]
  • GianFabien 13 hours ago

    I can't bring myself to like or to learn Zig syntax. BUT I do appreciate the cross-compilation capabilities of Zig and use it with C source codes. I find the Zig way of supporting multiple instruction sets and run-time environments simpler to grok than the GCC/Clang approach.

    One day, I might use the Zig tooling to translate my C sources to Zig sources and continue development in Zig from that point forwards.

    • jakeStbu 12 hours ago

      Yeah building a C cross compiler can certainly be a pain. I do feel like basically every Zig improvement over C also exists with Rust, though, including, yes, ease of cross compilation.

  • troymc 15 hours ago

    Maybe ask ChatGPT?

    • jakeStbu 15 hours ago

      ChatGPT is not particularly smart and tends to generate answers which should not be trusted. Of course, I have done Google searches before this, but most of them just point to the same answer - "It's C but simpler".

      • troymc 15 hours ago

        In some ways, Zig is simpler than C, it's true, but it also adds some nice things.

        For example, Zig introduces a robust error handling mechanism (try, catch, return err) that eliminates the need for exceptions or manual error checking via return codes (if (ret < 0)).

        Also, Zig includes its own build system (zig build) and package management. This removes the need for external tools like make, cmake, or third-party dependency managers. Everything is integrated and works cross-platform out of the box.

        You wondered why getting rid of macros was a good idea...

        Zig allows compile-time function execution (CTFE) as a core language feature. This replaces the need for macros in many cases. While C macros are powerful, they are also error-prone and hard to debug. Zig's comptime feature allows you to write functions that run during compilation, offering the same benefits but with stronger type safety and clearer error messages.

        • jakeStbu 15 hours ago

          I see. Better error handling could perhaps be something that C can improve, yes, especially as compared to things like errno (which yes is technically not C specific but rather Linux specific, but it would be good to have a layer of abstraction over this). I can see why Zig Build may be useful - does it have any major advantages over something like, say, Rust's Cargo? I personally find that to be quite powerful. CTFE does sound like it could be easier to debug, but it sounds significantly less powerful and I don't think that it's necessarily worth it in many cases.

  • ArtixFox 10 hours ago

    [dead]