DzLox

:)
git clone https://git.sr.ht/~ashymad/DzLox
Log | Files | Refs | Submodules | LICENSE

commit 0b5ab71eeb4a5cefdba78b089c6ee16854ad93ec
parent ccee14b0d2855d4b35f1e6fdabe8e44974b6d902
Author: Szymon Mikulicz <szymon.mikulicz@posteo.net>
Date:   Fri,  2 Oct 2026 23:11:57 +0200

Zero out the type

Diffstat:
Mzlox/src/lib::utils.zig | 12+++++++++++-
1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/zlox/src/lib::utils.zig b/zlox/src/lib::utils.zig @@ -155,9 +155,19 @@ pub fn enumFromStruct(str: type, backing: type) type { ); } +pub fn zero(ptr: anytype) void { + @memset(@as([*]u8, @ptrCast(ptr))[0..@sizeOf(@TypeOf(ptr))], 0); +} + +pub fn zeroed(typ: type) typ { + var ret: typ = undefined; + zero(&ret); + return ret; +} + pub fn typepun(Ret: type, val: anytype) Ret { if (@alignOf(@TypeOf(val)) < @alignOf(Ret)) { - var ret: Ret = undefined; + var ret = zeroed(Ret); @as(*@TypeOf(val), @ptrCast(&ret)).* = val; return ret; } else {