Re:Catch-23: The New C Standard Sets the World on Fire
by chongli on Sunday April 02, 2023 @06:11AM
(#35408992)
That's not the correct syntax for the ckd_ operations. They take 3 operands, the first being a pointer to an integer where the result should be stored. And they return a bool, which you need to check in a conditional. If you're just going to throw out the bool and ignore the overflows, why bother with checked operations in the first place?
[ Parent
| on HN ]
Re:Catch-23: The New C Standard Sets the World on Fire
by xigoi on Sunday April 02, 2023 @06:45AM
(#35409171)
Yeah, I realize that now. That's even worse. So you'll have to write something like
int aa,twoa,twoab,bb,aaplustwoab,aaplustwoabplusbb;
if (ckd_mul(a,a,&aa)) { return error; }
if (ckd_mul(2,a,&twoa)) { return error; }
// …
if (ckd_add(aaplustwoab,bb,aaplustwoabplusbb)) { return error; }
return aaplustwoabplusbb;
So ergonomic!> If you're just going to throw out the bool and ignore the overflows, why bother with checked operations in the first place?
I'd expect the functions to return the result on success and crash on failure. Or better, raise an exception, but C doesn't have exceptions…