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 πŸ’…πŸ’–πŸŒˆ