Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I can't seem to find any details on safety other than

> Safe: Optimality may be sitting in the driver's seat, but safety is sitting in the passenger's seat, wearing its seatbelt, and asking nicely for the other passengers to do the same.

Is Zig memory-safe? How? (Specifically, is there some useful safe subset ignoring the obvious FFI and "explicitly unsafe operations" exceptions every language gets?)

If it's not, is that even a goal?



It's not memory safe.

There is some compile time safety and some runtime safety, but it's not comprehensive.

Nullable pointers are handled by the type system at compile time.

Integer wrapping (signed or unsigned) will crash at runtime, unless you use explicit wrapping operators.

Array out of bounds will crash at runtime for slices.

There is no direct pointer arithmetic, but you can convert a pointer to a slice, and then index into the slice (which has array bounds checking). This is an example where the language is unsafe but it sort of guides the programmer into writing safe code.


Not being memory-safe is a bit of a bummer. Do you have a story for taking advantage of all the tooling thats been built up to defend against C's pervasive unsafety? Sanitizers being the most notable.

On balance even without them this'll probably be safer than C (as long as you're avoiding like, 90% of its pitfalls).

Either way, hope this works out for ya!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: