Zig
Peter Hull

Has anyone else come across the programming language Zig?
https://ziglang.org/
It's being developed as a replacement for C and it has good interoperability with C libraries. It has some interesting features like the way it handles errors.
I had a quick go at using it with Allegro - I just translated the ex_blit example. This was fairly straightforward and performance was similar to the original. However I'm not convinced it was a massive improvement either, although I'm sure if it were written as a Zig program (rather than a conversion) it would make better use of the features.
Have a look here:
https://github.com/pedro-w/zigallegro/blob/master/src/main.zig
(also, it does have coroutines, so David will be happy!)

Bob

I have to say that I don't have a good reason to use C or C++ for personal projects anymore.

C --> Zig
C++ --> D

The massive improvements with Zig is that it's harder to accidentally create some classes of bugs. E.g. many buffer or integer overflow bugs are caught at compile time.

Peter Hull

Good to hear you've been working with Zig. I found it a bit tricky as the docs are not great and it's still being changed frequently. For example it's not possible to pass or return ALLEGRO_COLOR by value because of some limitations in the compiler which are due to be fixed in the future. I suspect in my zig code I've done things which are weird just because I wasn't sure of the optimal way to do them.
I don't know Rust but I think the zig syntax bears a superficial resemblance to it, what do you think?

Bob

I've only written trivial programs in Zig (basically, the examples in the website to get a feel for the language). So my experience is very limited.

I typically use D or Python by default now.

Niunio

I think Zig is the first C replacer that actually convinces me. I should test it.

David Couzelis

(also, it does have coroutines, so David will be happy!)

;D!! I haven't heard of Zig before, I'll have to check it out! :)

Doctor Cop

Zig is love, Zig is life. Wren is kinda also the same, but I always use C, it's my Goto unless I can't think of a solution in C and I have to choose the wicked C++. Even then I don't easily go for Zig and other languages for some reason.

Edgar Reynaldo

I prefer Zag. You know, to keep 'em guessing.

bamccaig

I've never heard of Zig before. That's exciting! :D

Though I already think of Rust as a C killer. And it is pretty neat too.

I hope people have interoperability on their radar so that code written in one is linkable and callable from another. Just to save on the square wheels.

Niunio

Ok, you can call C functions from Zig out-of-the-box, but what about the other way? I mean call Zig functions from C (or other language). Didn't found information about it.

Peter Hull

It's this section:
Export functions, variables, and types for C code to depend on

For example, in my conversion of ex_blit to zig mentioned above, I have here

export fn user_main(argc: c_int, argv: [*c][*c]u8) c_int {
    if (!a5.shim_init()) {
        abort_example("Could not init Allegro.\n");
    }
...

which is called by al_run_main (a C function) from Zig's own main. The signature of that function is the Zig equivalent of int user_main(int argc, char* argv[]) which will be familiar to you.

RmBeer2

Cute, another garbage language that mimics C and creates a cool name for the language. Another for the landfill.

Thread #618226. Printed from Allegro.cc