2 ms·
> Well so Zig pointers, by default, has more UB than Rust pointers, at least when concerning null pointers. Not quite. In Zig, a (non-C) pointer type is closer
by hansvm 2y ago
> Well so Zig pointers, by default, has more UB than Rust pointers, at least when concerning null pointers.
Not quite. In Zig, a (non-C) pointer type is closer to a Rust reference in its behavior. It isn't null, and that's enforced by the type system.
The author's point about opting into nullability is that in a function signature you can choose to allow null pointers to be passed to the function by making the argument type an optional pointer, a weaker type with the same safety guarantees (because, like with Rust, the type system forces you to handle the null branch).