Take off every Zig!
I don't know how to do that exactly. The closest I could come up with would be to leave the array undefined and use a helper function to fill it in, but that has slightly different semantics since the memcpy is a little more explicit:
undefined
memcpy
fn init_array(target: anytype, items: ?[]const std.meta.Elem(@TypeOf(target))) void { const T = std.meta.Elem(@TypeOf(target)); if (items) |slice| { std.mem.copy(T, target, slice); std.mem.set(T, target[slice.len..], std.mem.zeroes(T)); } else { std.mem.set(T, target, std.mem.zeroes(T)); } } var foo: [50]u8 = undefined; init_array(&foo, "foo"); var a = A{.foo = undefined}; init_array(&a.foo, "foo");
Good solution. I haven't seen std.meta.Elem before so I'm going to go read up on that. Thanks!
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
I don't know how to do that exactly. The closest I could come up with would be to leave the array
undefined
and use a helper function to fill it in, but that has slightly different semantics since thememcpy
is a little more explicit:Good solution. I haven't seen std.meta.Elem before so I'm going to go read up on that. Thanks!