← Back to context

Comment by ralphc

14 hours ago

How does "Modern" C compare safety-wise to Rust or Zig?

There's finally a way to safely add two signed numbers, without tricky overflow checks that may trigger UB themselves!

Modern C still promptly decays an array to a pointer, so no array bounds checking is possible.

D does not decay arrays, so D has array bounds checking.

Note that array overflow bugs are consistently the #1 problem with shipped C code, by a wide margin.

You'd be surprised: Zig has one UB (Undefined Behaviour) that C doesn't have!

In release fast mode, unsigned overflow/underflow is undefined in Zig whereas in C it wraps.

:-)

Of course C has many UBs that Zig doesn't have, so C is far less safe than Zig, especially since you can use ReleaseSafe in Zig..

Modern C is barely any different than older C. The language committee for C is extremely conservative, changes tend to happen only around the edges.