Menu

#749 Checked integer arithmetic

None
open
nobody
None
5
2022-08-09
2021-06-15
No

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.

Related

Bugs: #3254
Bugs: #3255
Bugs: #3798
Wiki: SDCC-STD-UX

Discussion

  • Philipp Klaus Krause

    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -10,4 +10,4 @@
     ~~~~
    
     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 bug [#3254] first.
    +Implementing these for SDCC would require fixing bugs [#3254] and [#3255] first.
    
    • Group: -->
     

    Related

    Bugs: #3254
    Bugs: #3255

  • Philipp Klaus Krause

    In 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).

     
  • Philipp Klaus Krause

    In [r13650] checked integer arithmetic is implemented for all required types except (unsigned) long long.

     

    Related

    Commit: [r13650]


Log in to post a comment.

MongoDB Logo MongoDB