SDL_memcmp(3)

πŸ’– SDL_memcmp(3) β€” the vibe check for your memory buffers πŸ’–

okay so bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where today we're doing SDL_memcmp β€” literally the function that looks at two chunks of memory and is like "hmm, who's bigger tho" ✨


🌸 NAME 🌸

SDL_memcmp β€” compare two buffers of memory. that's it, that's the whole job, and she does it flawlessly πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_stdinc.h>

int SDL_memcmp(const void *s1, const void *s2, size_t len);

look at her. short. iconic. no notes. 🫢


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • s1 β€” the first buffer to compare. and listen, NULL is not permitted! like, do NOT pass NULL, she will not be chill about it 🚫😭
  • s2 β€” the second buffer to compare. same energy, NULL is not permitted! fr fr, do not do it πŸ™ˆ
  • len β€” the number of bytes to compare between the buffers. so like, how far down the line are we checking? you decide, bestie πŸ¦‹

πŸ‘‘ RETURN VALUE πŸ‘‘

she gives you a whole int and honestly the number is telling you a story:

  • less than zero β†’ s1 is "less than" s2 πŸ’€
  • greater than zero β†’ s1 is "greater than" s2 πŸ”₯
  • zero β†’ the buffers match exactly for len bytes πŸ₯³ slay

so yeah, zero is the good one. zero means they're twins. πŸ‘―


🧚 THREAD SAFETY 🧚

good news babes β€” it is safe to call this function from any thread. no drama, no locking, no gatekeeping. every thread can pull up 🌈


⭐ AVAILABILITY ⭐

this one's been around since SDL 3.2.0. so if you're on something older… girl, upgrade 😭


lowkey reminder: this is the memory-comparing sister of the whole string-compare family, so if you know her, you know her. iykyk πŸ’œ

and that's the tea, bestie! this page came to you from Simple Directmedia Layer, living in SDL 3.4.18, filed under SDL_memcmp(3) in the SDL3 FUNCTIONS collection. mwah, go compare some buffers responsibly πŸ’–πŸ’…βœ¨

πŸ“¦ where this page comes from