News for hackers. Stuff that matters.
Re:Checked integer arithmetic in the prospect of C23 by tinglymintyfrsh on Monday December 19, 2022 @01:32PM (#34055713)
tl;dr

    #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);



    #include <stdckdint.h>
    #include <limits.h>

    /* ... */
    int x;
    int a = INT_MAX;
    int b = INT_MAX;

    if (!chk_add(&x, a, b)) {
       /* error! */
    }
Other stuff on the table for C23

- https://thephd.dev/c-the-improvements-june-september-virtual...

- (PDF) https://open-std.org/jtc1/sc22/wg14/www/docs/n3054.pdf

Re:Checked integer arithmetic in the prospect of C23 by heywhatupboys on Monday December 19, 2022 @01:53PM (#34056017)
> if (!chk_add(&x, a, b)) { > /* error! */ > }

does it return non-zero on success???

Re:Checked integer arithmetic in the prospect of C23 by tinglymintyfrsh on Monday December 19, 2022 @02:15PM (#34056292)
They're using a bool, so it violates the old-school C paradigm used for library calls. This is more of a macro rather than a syscall or standard library function call.
Re:Checked integer arithmetic in the prospect of C23 by comex on Monday December 19, 2022 @02:25PM (#34056429)
It returns a bool, but true means error, not false.
Re:Checked integer arithmetic in the prospect of C23 by ronsor on Monday December 19, 2022 @11:41PM (#34061624)
It's not really an error. The function is just "check if this addition overflows" and tells you true, it does overflow, or false, it doesn't.
Re:Checked integer arithmetic in the prospect of C23 by EdSchouten on Monday December 19, 2022 @02:15PM (#34056288)
It returns a boolean.
Re:Checked integer arithmetic in the prospect of C23 by comex on Monday December 19, 2022 @02:24PM (#34056420)
You have it backwards: it returns true on error.
Re:Checked integer arithmetic in the prospect of C23 by RustyRussell on Monday December 19, 2022 @05:18PM (#34058550)
Let's take this as evidence that the proposal is counter-intuitive?