SDL_CompareCallback(3type)

πŸ’– SDL_CompareCallback πŸ’–

okay so bestie, welcome to the <SDL3/SDL_stdinc.h> corner of the SDL3 datatypes era β€” this one's a 3type page, and it's all about the callback you hand over to SDL's sorting and binary search girlies. no cap, it's lowkey the whole personality of SDL_qsort and SDL_bsearch. 🫢


✨ NAME ✨

SDL_CompareCallback β€” a callback used with SDL sorting and binary search functions.

like, the little function you write so SDL knows which element goes first. it's giving main character energy for your comparator logic. πŸ‘‘


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_stdinc.h>

typedef int (SDLCALL *SDL_CompareCallback)(const void *a, const void *b);

yes the SDLCALL is right there, don't skip it, it's doing important work. πŸ’…


πŸŽ€ FUNCTION PARAMETERS πŸŽ€

  • a β€” a pointer to the first element being compared.
  • b β€” a pointer to the second element being compared.

that's it. two pointers. two little guys. you compare them. iconic. ✨


πŸ¦‹ RETURN VALUE πŸ¦‹

so here's the vibe check your function has to pass:

  • returns -1 if a should be sorted before b
  • returns 1 if b should be sorted before a
  • returns 0 if they are equal
⚠️ and listen, if two elements are equal, their order in the sorted array is undefined. literally nobody promised you stability here, so don't come for me when your equal elements shuffle around. it's not a bug, it's just how it is. 😭

🌈 AVAILABILITY 🌈

this callback is available since SDL 3.2.0. so if you're on anything older, bestie… it's not gonna be there. πŸ™ˆ


πŸ’œ SEE ALSO πŸ’œ

those are the two functions that actually call your little callback, so go read them next, fr fr. πŸ“š


mwah, that's the whole page β€” go forth and sort responsibly. 🧚

this one comes to you from the Simple Directmedia Layer girlies, running SDL 3.4.18 β€” SDL_CompareCallback(3type), signing off. slay, bye!! πŸ’–πŸŽ€πŸŒΈ

πŸ“¦ where this page comes from