Integer overflow checking with C23
blog.gnoack.org·1d
Flag this post

November 2, 2025

While I wasn’t looking, C23 has standardized checked integer arithmetic functions, replacing the old “__builtin_mul_overflow()” compiler intrinsics that shipped with GCC and Clang.

#include <stdckdint.h>
bool ckd_add(type1 *result, type2 a, type3 b);
bool ckd_sub(type1 *result, type2 a, type3 b);
bool ckd_mul(type1 *result, type2 a, type3 b);

The operations are performed equivalently to doing them in the mathematically reasonable way (as normal integers in ℤ, not modulo-something), and then trunc…

Similar Posts

Loading similar posts...