FMT_COPYBYTES_SIZEOF_MINUS1(3)

✨ fmt_copybytes_sizeof_minus1 ✨

okay bestie, we're in the Library Functions Manual section 3 today and the star of the show is literally called fmt_copybytes_sizeof_minus1 πŸ’… she's a mouthful but she's iconic


πŸŽ€ NAME πŸŽ€

fmt_copybytes_sizeof_minus1 β€” write binary data πŸ¦‹


🌸 SYNTAX 🌸

#include <libowfat/fmt.h>

size_t fmt_copybytes_sizeof_minus1(char *dest,const char *source);

πŸ’– DESCRIPTION πŸ’–

okay so listen. this macro copies sizeof(source)-1 bytes from source into dest. that's it, that's the whole vibe ✨

it's giving convenience wrapper energy β€” a lil interface around fmt_copybytes for when you're building a binary message by smashing together hex constant strings, like this:

fmt_copybytes_sizeof_minus1(dest, "\x01\x02\x03\x04");

now here's the tea β˜• because source is technically a string, the compiler sneaks a 0 byte onto the end, and sizeof() will hand you the size including that lil 0 byte. which is rude. so that's literally why there's a minus 1 in this function β€” so we do NOT copy it and we do NOT count it. problem solved, periodt 🫢


πŸ‘‘ NOTE πŸ‘‘

⚠️ Caution bestie: source must not have side effects, or those side effects will be evaluated twice. no cap, be careful πŸ™ˆ

πŸ’œ SEE ALSO πŸ’œ


that's the whole page fr fr β€” sending you love from the Library Functions Manual, section 3, where fmt_copyby...zeof_minus1(3) lives rent free πŸŒˆπŸ’– go forth and copy those bytes, you got this 🧚