sub_of(3)
β¨ sub_of(3) β¨
okay bestie, welcome to the Library Functions Manual π this is the page for sub_of, and it's lowkey one of the most useful little gremlins in the whole family. sit down, hydrate, let's go π«Ά
πΈ NAME πΈ
sub_of β subtract two integers, and check for arithmetic overflow π
like. that's it. that's the whole job. subtract. but safely. iconic behavior honestly.
π¦ SYNTAX π¦
#include <libowfat/rangecheck.h>
int sub_of(dest,a,b);
yes queen, include the header first, always π
π DESCRIPTION π
so here's the vibe check π
If calculating a-b is possible without causing undefined behavior or an arithmetic overflow in C, and the result actually fits into the destination integer type, then it goes ahead and does dest=a-b and returns 0. slay. no drama. β¨
Otherwise? It returns 1. that's the "nope, absolutely not, that would have been a whole disaster" signal π
π‘ Note: This is a macro, so dest does not have to be a pointer. bestie you can just hand it a plain old variable. no asterisks required. we love an accessible queen π
π BUGS π
okay this is the part where you have to PAY ATTENTION because it's genuinely confusing and it has bitten people fr fr π
In the multiplication functions, a return value of 1 signals success and 0 signals failure.
In add_of, sub_of and assign it's the other way around. π
so like. read the return value carefully. don't just assume. i'm begging you. π
π SEE ALSO π
your new besties, go say hi π«Ά
and that's the page!! sub_of(3), straight from the Library Functions Manual, exactly as it was written, just with way more sparkle β¨ go forth and subtract safely, bestie β no overflow, no undefined behavior, only vibes π
ππ
π¦ 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