Hey @houghtonap, thanks for the article. It looks like you’ve got a small bug in your program: const len = text.len; ... const last = if (this.end > len) len else end; return text[first .. last + 1]; If last is equal to text.len, then this will read one index beyond the end of the string. I’d recommend changing those lines to: const last = @min(this.end + 1, text.len); return text[first..last]; Personally, I’d just keep it to non-inclusive ranges to be consistent, but I get that you’r...| Ziggit
This library overwrites malloc, realloc, calloc and free in a c module with functions that call into a zig allocator. Perhaps it is a really stupid idea but I thought it would be fun.| Ziggit
Hi, I’ve just finished coding up and debugging a 1D and 3D shock physics benchmark for Zig: The larger 3D Zig benchmark runs about 15% faster than the C reference implementation compiled with gcc -O3 on my machine ( which is faster than gcc -O2). I used the aarch64 tarball off the download page to do my run. I notice that there are a lot of unexploited “low hanging fruit” peephole optimization opportunities in the FP assembly language, e.g. fmadd/fmsub/fnmsub. ZIg can only get much fast...| Ziggit
A community for anyone interested in the Zig Programming Language.| Ziggit
Complete Example const std = @import("std"); pub fn main() !void { const StartingState = Witness(Example.Exit, Example.AOrB(Example.State1, Example.State2)); var gst: GlobalState = .init; sw: switch (StartingState.transition(&gst)) { .Current => |function| { continue :sw function(&gst); }, .Exit => {}, } } pub const GlobalState = struct { counter: u64, prng: std.Random.DefaultPrng, pub const init: GlobalState = .{ .co...| Ziggit
The following code results in i being 2. I think it might be a bug in Zig, but it’s sufficiently confusing that I’m not sure. Is this expected behavior? What’s going on? fn nop() error{E}!void {} pub fn main() !void { comptime var i = 0; { defer { i += 1; } try nop(); } @compileLog(i); // outputs 2 }| Ziggit
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. – Antoine de Saint-Exupéry| Ziggit
A community for anyone interested in the Zig Programming Language.| Ziggit
I’ve been looking into Zig for a couple of days now, digging deeper and deeper in search of conceptual flaws and weaknesses in its design, and I’ve found… zero! Replacing C isn’t easy—not so much because of the vast amount of existing code and libraries, but because, in low-level and systems programming, C is absolutely lethal. So, finding a modern replacement for it is a real challenge. There are three possible candidates: D, Rust, and Zig. In my opinion, D would be the top choice ...| Ziggit
I need to traverse the various versions of the syntax tree in my compiler and I’d like to do this in a generic way. I have implemented this previously but I’m unsatisfied with my solution. Is there a better way?| Ziggit
Hey everyone, I’ve been thinking about how I initialise stack-allocated buffers in Zig, and I’ve found myself consistently leaning towards std.mem.zeroes rather than undefined. For example, I’ll typically write: var buf = std.mem.zeroes([256]u8); Instead of: var buf: [256]u8 = undefined; My reasoning is primarily around robustness and clarity. It feels “safer” to me to explicitly zero out a buffer, especially when parts of it might not be immediately overwritten, avoiding potential ...| Ziggit
A community for anyone interested in the Zig Programming Language.| Ziggit
A community for anyone interested in the Zig Programming Language.| Ziggit
A community for anyone interested in the Zig Programming Language.| Ziggit
I’m running into strange behavior with zig build run, and I’m hoping others might help explain what’s happening. I have a simple Zig app that I can run with zig build run. But if I run the compiled binary afterwards, the performance is 10x worse than with zig build run. src/main.zig const std = @import("std"); pub fn countBytes(reader: anytype) !u32 { var count: u32 = 0; while (true) { _ = reader.readByte() catch |err| switch (err) { error.EndOfStream => { ...| Ziggit