Live data from Hacker News

Using Zig to Unit Test a C Application

mtlynch.io

51–54 of 54 posts

Re: Using Zig to Unit Test a C Application

#51
post #31

Earlier quoted context omitted.

Yes: https://dlang.org/spec/importc.html The D compiler(s), as Zig, can be used to compile C code... and D code can import C files as if they were D modules (as in Zig, there are some special types to represent C strings and other types that are not exactly the same).

Thanks for that! I'm a big fan of D, as someone who primarily codes in C# and Python. I really wish a big company would take on D in a serious way that puts it on the map significantly. It is an underrated language in my opinion.

Absolutely. It was way ahead of its time. And it's improving, albeit slowly. With stuff like @safe, @nogc, pure, betterC[1], and its unmatched metaprogramming, it's a more modern language than most of the newer languages popping up.

[1] https://dlang.org/blog/2017/08/23/d-as-a-better-c/

Re: Using Zig to Unit Test a C Application

#52
Great use case and a possible killer app for Zig.

However, for the complete newcomer to Zig, this post seems a bit convoluted in this presentation.

What about the Zig authors do a step by step tutorial on how to leverage Zig to implement tests in a C codebase?

Would be a great entry point for the broader community!

Re: Using Zig to Unit Test a C Application

#53
post #2

I've done this where I use python's ctypes library to write tests for a c codebase. This feels very similar in that it can be tricky to get the type interop correct the first time around. What other strategies/solutions do people like to use for testing their c projects?

I think (but I'm not sure) that in Zig you can just @cInclude("header.h") or something like that? So your C types are automatically imported/converted to Zig types.

Re: Using Zig to Unit Test a C Application

#54
post #51

Earlier quoted context omitted.

Thanks for that! I'm a big fan of D, as someone who primarily codes in C# and Python. I really wish a big company would take on D in a serious way that puts it on the map significantly. It is an underrated language in my opinion.

Absolutely. It was way ahead of its time. And it's improving, albeit slowly. With stuff like @safe, @nogc, pure, betterC[1], and its unmatched metaprogramming, it's a more modern language than most of the newer languages popping up. [1] https://dlang.org/blog/2017/08/23/d-as-a-better-c/

If someone would hire me to use it, I would take the offer in a heartbeat. Until then I just play with it to test out language features and check it out. I wanted to like Vibe.d but I wanted something a little more batteries included. I might check out the Hunt Framework though.
Post reply on HN