Get the latest tech news
Packed structs in Zig make bit/flag sets trivial
As we've been building Mach engine, we've been using a neat little pattern in Zig that enables writing flag sets more nicely in Zig than in other languages. Here's a brief explainer.
The Zig compiler will take care of running the comptime code block here for us when building, and it will verify that the byte size of@This()(the type we’re inside of, the ColorWriteMaskFlags struct in this case) matches the@sizeOf(u32). Be sure to join the new Mach engine Discord server where we’re building the future of Zig game development. I just hate masking to check if bits are set, and the insane number of ways that exact same logic can be written - both correctly and incorrectly.
Or read this on Hacker News