Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Zig

This thread is locked; no one can reply to it. rss feed Print
Zig
Peter Hull
Member #1,136
March 2001

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
Free Market Evangelist
September 2000
avatar

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.

--
- Bob
[ -- All my signature links are 404 -- ]

Peter Hull
Member #1,136
March 2001

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
Free Market Evangelist
September 2000
avatar

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.

--
- Bob
[ -- All my signature links are 404 -- ]

Niunio
Member #1,975
March 2002
avatar

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

-----------------
Current projects: Allegro.pas | MinGRo

David Couzelis
Member #10,079
August 2008
avatar

(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
Member #16,833
April 2018
avatar

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
Major Reynaldo
May 2007
avatar

bamccaig
Member #7,536
July 2006
avatar

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
Member #1,975
March 2002
avatar

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.

-----------------
Current projects: Allegro.pas | MinGRo

Peter Hull
Member #1,136
March 2001

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
Member #16,660
April 2017
avatar

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

🌈🌈🌈 🌟 BlackRook WebSite (Only valid from my installer) 🌟 C/C++ 🌟 GNU/Linux 🌟 IceCream/Cornet 🌟 🌈🌈🌈

Rm Beer for Emperor 2021! Rm Beer for Ruinous Slave Drained 2022! Rm Beer for Traveler From The Future Warning Not To Enter In 2023! Rm Beer are building a travel machine for Go Back from 2023! Rm Beer in an apocalyptic world burning hordes of Zombies in 2024!

Go to: