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
-1ifashould be sorted beforeb - returns
1ifbshould be sorted beforea - returns
0if 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
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 43: SDL3-devel 3.4.18-1.fc43 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- fedora 44: SDL3-devel 3.4.18-1.fc44 Β· Zlib AND MIT AND Apache-2.0 AND (Apache-2.0 OR MIT)
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms