C23 introduced stdchkint.h, for checked integer arithmetic, e.g.
int *r, a, b;
…
if(ckd_add(r, a, b))
{
printf("Overflow!\n");
}
The ckd_add, ckd_sub, ckd_mul macros allow to perform arithmetic, and check for overflow (with no undefined behaviour happing): *r will hold the result (as if computed to infinite precision and then cast to the type of *r).
Implementing these for SDCC would require fixing bugs [#3254] and [#3255] first.
Diff:
Related
Bugs:
#3254Bugs:
#3255In C23, support for checked bit-precise integers will not be mandatory (as decided by WG14 yesterday). While we might want to support them later, for now we can focus on checked integer arithmetic for the standard integer types (AFAIK SDCC currently does not support any extended integer types).
In [r13650] checked integer arithmetic is implemented for all required types except (unsigned) long long.
Related
Commit: [r13650]