Zig NEWS

Discussion on: Crafting an Interpreter in Zig - part 1

Collapse
 
ityonemo profile image
Isaac Yonemoto • Edited

while my mind is blown by the realloc return signature i wonder if it wouldn't be more readable as a function call?

fn reallocReturnFor(comptime T: type) type {
  const Slice = @typeInfo(T).Pointer;
  return Error![]align(Slice.alignment) Slice.child;
}

pub fn realloc(self: *Allocator, old_mem: anytype, new_n: usize) reallocReturnFor(@TypeOf(old_mem) {
...
}
Enter fullscreen mode Exit fullscreen mode