add_of(3)
π add_of(3) β the little overflow-checker that could π
okay bestie, gather round, because today we're talking about add_of, a function from the Library Functions Manual and honestly? she's doing the most for you and you don't even know it yet.
β¨ NAME β¨
add_of β add two integers, and check for arithmetic overflow π«Ά
like. she adds. she checks. she's an icon.
πΈ SYNTAX πΈ
#include <libowfat/rangecheck.h>
int add_of(dest,a,b);
that's it, that's the whole vibe. include the header, call the macro, live your truth. β¨
π¦ DESCRIPTION π¦
so here's the tea β: if calculating a+b is possible without causing undefined behavior or an arithmetic overflow in C, and the sum actually fits into the destination integer type? she does dest=a+b and returns 0. slay. no cap.
otherwise? she returns 1. that's it. that's the whole girl. π
π Note, bestie: this is a macro, so dest does not have to be a pointer. yeah. you heard me. iconic behavior honestly.
π BUGS π
okay so this is the part where things get a lil chaotic and we need to talk about it π
in the multiplication functions, a return value of 1 signals success and 0 signals failure.
but in add_of, sub_of and assign? it's the other way around. π
so like. read the return value carefully. do not get got. i'm begging you. π«Ά
π SEE ALSO π
go read them too, they're all part of the same friendship group β¨
and that's the whole page, bestie π shoutout to the Library Functions Manual for hosting her, and shoutout to add_of(3) herself for being the responsible one who checks before she sums. stay safe out there and always check your overflow, ily ππ¦πΈ
π¦ where this page comes from
- alpine 3.24: libowfat-doc 0.34-r0 Β· GPL-2.0-only
- debian bookworm: libowfat-dev 0.32-4 Β· GPL-2.0-only
- debian trixie: libowfat-dev 0.32-5 Β· GPL-2.0-only
- nixos 26.05: libowfat 0.34
- nixpkgs unstable: libowfat 0.34
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- opensuse-leap 16.0: libowfat-devel 0.33-bp160.1.11 Β· GPL-2.0-only
- ubuntu noble: libowfat-dev 0.32-4.1build1 Β· GPL-2.0-only
- ubuntu questing: libowfat-dev 0.32-5
- ubuntu resolute: libowfat-dev 0.34-2 Β· GPL-2.0-only
- ubuntu stonking: libowfat-dev 0.34-2 Β· GPL-2.0-only
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms