4 ms·
How does zig handle this? Does it just have its own slice representation that gets compiled away? Or does it disallow zero length slices?
by pyrolistical 3y ago
How does zig handle this? Does it just have its own slice representation that gets compiled away? Or does it disallow zero length slices?
- anonymoushn 3y agoZig slices are (start, count) where start's type is non-nullable pointer. My impression is that Zig doesn't have a documented memory model that cares about things like whether an address corresponds to an allocation or not, so problems relating to this sort of thing cannot come up yet :)
- brabel 3y agoI am not entirely sure, but it seems they chose to return a null pointer: https://github.com/ziglang/zig/commit/32e0dfd4f0dab351a024e7680280343db5d7c43e https://github.com/ziglang/zig/commit/32e0dfd4f0dab351a024e7...
- anonymoushn 3y agoThis is a commit that changes the now-defunct Zig compiler written in C++ to be careful when it calls malloc. So it has nothing to do with the semantics of the Zig language or the compatibility of zero-sized Zig slices with Rust, C, or C++ APIs.