How to return early without "unreachable code" error
Ziggit
How to return early without "unreachable code" error
If you want to return from the middle of a function (such as when prototyping), Zig’s compiler will not let you just do this: fn foo() void { var x: i32 = 0; return; x += 1; // ERROR: unreachable code (because of the `return` above) std.debug.print("{d}", .{x}); } I have recently found out about these two ways of circumventing this. Instead of return; you can do: if (true) return; (return)(); The second one is cool, because it abuses coercing the noreturn type of the re...
0 comments
No comments yet.