3 ms·
> Aside from lack of community I’d say the biggest nuisance is error handling in nearly everything including allocations. I get that allocation can fail but the
by loeg 3y ago
> Aside from lack of community I’d say the biggest nuisance is error handling in nearly everything including allocations. I get that allocation can fail but the vast majority of programs I write, I just want to panic on an allocation failure (granted these aren’t production programs…)
The C strategy for this was just to wrap malloc() with something called xmalloc or malloc_nofail or whatever:
void *malloc_nofail(...) {
void *res = malloc(...);
if (res == NULL) {
abort();
}
return res;
}
(Or whatever.) The same would work in Zig, I think.
- helen___keller 3y agoYes you can easily make a one liner allocation function in zig that takes an allocator as input with a comptime type and panics if allocation fails and returns the unwrapped allocation I just say nuisance because zig code often looks like Go code in that almost every return type becomes an error union as allocation error handling (and maybe other errors) trickle up
- TylerE 3y agoFrom my experience with Zig (limited but not zero) it seems like an ok solution to a problem I don't have, and don't forsee having.