49 ms·
Just to be clear, Zig isn't the same as C/C++ with sanitizers. Zig has slices and it doesn't have pointer arithmetic and pervasive casts. For example, if you
by pron 6y ago
Just to be clear, Zig isn't the same as C/C++ with sanitizers. Zig has slices and it doesn't have pointer arithmetic and pervasive casts. For example, if you preallocate a buffer and then reuse it, or chunk it into multiple pieces, sanitizers won't find an issue, but Zig will (thanks to slices). C simply has no way to express, "I want to pass a pointer into an array to this subroutine but it is only allowed to use n elements," when n is dynamic.
- pjmlp 6y agoC++ has it though, https://github.com/microsoft/GSL/blob/master/include/gsl/span https://github.com/microsoft/GSL/blob/master/include/gsl/spa...
- pron 6y agoRight, but in this case it's not a matter of what you have, but what you don't. Zig has slices as the only form of moving pointers around, and it doesn't have any pointer arithmetic. I.e. every time some data is traversed, the language ensures the size is known either at compile time or runtime.
- pjmlp 6y agoFor the time being, https://github.com/ziglang/zig/issues/2018 https://github.com/ziglang/zig/issues/2018
- pron 6y agoThis isn't exactly pointer arithmetic as in C (or in unsafe Zig, as with @intToPtr, or using the "unknown size" pointer type, [*]). This is talking about preserving size information, and only when the arithmetic is compile-time-known; so it's more "array arithmetic".
- pjmlp 6y agoFair enough.