#include <stdckdint.h>
//no range check: unsigned arithmetic wraps around
unsigned char b1 = 200;
unsigned char b2 = 100;
unsigned char b3 = b1 + b2;
//b3 is 44 (300 - 256)
//signed overflow (INT_MAX + 1) is undefined behavior;
//C23 ckd_add checks it and returns true on overflow
int sum1;
bool overflow1 = ckd_add(&sum1, INT_MAX, 1);
//overflow1 is true, sum1 is -2147483648 (the wrapped value)
int sum2;
bool overflow2 = ckd_add(&sum2, 2, 3);
//overflow2 is false, sum2 is 5
//ckd_sub and ckd_mul work the same way
long long product;
bool overflow3 = ckd_mul(&product, LLONG_MAX, 2);
//overflow3 is true
printf("b3 is %d\n", b3);
printf("overflow1 is %s\n", overflow1 ? "true" : "false");
printf("sum1 is %d\n", sum1);
printf("overflow2 is %s\n", overflow2 ? "true" : "false");
printf("sum2 is %d\n", sum2);
printf("overflow3 is %s\n", overflow3 ? "true" : "false");