MEMOVERLAP(3pub)

πŸ’– MEMOVERLAP πŸ’–

okay bestie, welcome to section 3pub of the C Programmer's Manual β€” the publib corner of the universe where we do pointer math so you don't have to. this one's called memoverlap, and it's genuinely one of those tiny little functions that just works and makes your whole life easier. ✨


🌸 NAME 🌸

memoverlap β€” check whether two memory blocks overlap 🫢


πŸŽ€ SYNOPSIS πŸŽ€

#include <publib.h>
int memoverlap(const void *t, size_t ts, const void *s, size_t ss);

✨ DESCRIPTION ✨

so like. memoverlap checks whether the memory blocks t--(t+ts-1) and s--(s+ss-1) overlap. that's it. that's the whole vibe. πŸ’…

two things you cannot do, no cap:

  • neither pointer argument may be NULL β€” not t, not s, periodt πŸ™…β€β™€οΈ

and two things you totally can do:

  • the sizes may be 0 β€” zero is a valid size, she's fine, she's thriving

the memory blocks can be arbitrary, bestie. they do not have to be part of the same array. like, at all. so that means this function is out here hiding the unportable pointer comparison that you would otherwise have to rely on yourself. it's giving "I'll handle the cursed part, you go live your life." πŸ‘‘


πŸ’€ RETURN VALUE πŸ’€

  • returns 0 if the blocks do not overlap 🚫
  • returns nonzero if they do overlap πŸ”₯

that's the whole contract. no surprises, no drama, no hidden states. obsessed. πŸŽ€


🌈 SEE ALSO 🌈

  • publib(3) β€” the whole fam, go say hi πŸ’œ

πŸ‘‘ AUTHOR πŸ‘‘

Lars Wirzenius (lars.wirzenius@helsinki.fi) β€” icon behavior, honestly. 🫢


ok that's the whole page!! now go forth and never accidentally memcpy over yourself again, bestie πŸ’–

Publib Β· C Programmer's Manual Β· MEMOVERLAP(3pub) β€” that's the source, the manual and the section, mwah, bye bye πŸ¦‹πŸŒΈβœ¨

πŸ“¦ where this page comes from