4 ms·
if you need to import a package to clear an array, something went very wrong somewhere..
by Shadonototra 5y ago
if you need to import a package to clear an array, something went very wrong somewhere..
- christophilus 5y agoWhy?
- Shadonototra 5y agobecause it's trivial, it's like assigning a value to an integer, it shouldn't require a package
- messe 5y agoDepending on your perspective, it's not trivial. It's significantly more expensive than assigning a value to an integer. Zeroing a [4096]u64 would require several thousand times more operations than zeroing a u64. In the areas that zig targets, this can be quite important.
- Shadonototra 5y agoi disagree, it's just backward to need to import a package
- kristoff_it 5y agoIn Zig zero initialization is not idiomatic. Unless you have an active reason to do so (and during AoC you need zero init a lot more than normal IME), you should just set the array to undefined like so: var foo: [64]usize = undefined;