Hacker News new | ask | show | jobs
by richardwhiuk 2456 days ago
> 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.

2 comments

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`.