Hacker News new | ask | show | jobs
by rhodysurf 2457 days ago
Can you give examples of the peculiarities? I write cpp all day and zig is a nice change for me because of how simple it is to me
1 comments

> Zig both signed and unsigned integers have undefined behavior on overflow, contrasted to only signed integers in C

make a feature unwanted in C, worse. nice.

debug and safe modes in zig disallow overflows entirely unless you specifically use the wrapping operator to clearly specify your intent. These checks are removed in speed-optimized builds.

In other words, the compiler will enforce that `a + b` does not overflow through all your testing and wherever you explicitly say such checks are required, but turns them into nops for you when you desire speed. You can let the compiler know that you explicitly want wrapping overflow (and not some undefined kind) using the wrapping operator `a +% b`.