3 ms·
> The ckd_* macros steer a refreshingly sane path around arithmetic pitfalls including C's "usual arithmetic conversions." A 7 letter function to add two numbe
by juunpp 4y ago
> The ckd_* macros steer a refreshingly sane path around arithmetic pitfalls including C's "usual arithmetic conversions."
A 7 letter function to add two numbers and that returns a boolean... not entirely sure I'd call that 'sane'.
- ludocode 4y agoI'd prefer if it were more letters. It bothers me when API designers omit random letters just to save a few keystrokes. These are particularly egregious because I keep forgetting which letters they kept. Is it "chk"? or "ckd"? or "chd"? or something else? I wrote a portability library that wraps these with compiler intrinsic and standard C fallbacks. I chose to spell out the full word in addition to making the type explicit. It's a lot more verbose of course but a lot clearer to read: https://github.com/ludocode/ghost/blob/develop/include/ghost/math/checked_add/ghost_checked_add_i32.h https://github.com/ludocode/ghost/blob/develop/include/ghost...
- goatlover 4y agoA saner language would handle the conversion for you so it would work with just the normal math operators.