SDL_CompareCallback_r(3type)
π SDL_CompareCallback_r π
okay bestie, so this is a page from the SDL3 DATATYPES corner of the manual β it's SDL_CompareCallback_r(3type), and it's literally the callback you hand over to SDL's sorting and binary search functions so they know how to compare your stuff. no cap, it's giving "tiny function, huge responsibility." π«Ά
β¨ NAME β¨
SDL_CompareCallback_r β a callback used with SDL sorting and binary search functions. that's it, that's the whole job, and she does it flawlessly π
πΈ SYNOPSIS πΈ
#include <SDL3/SDL_stdinc.h>
typedef int (SDLCALL *SDL_CompareCallback_r)(void *userdata, const void *a, const void *b);
look at that signature. so clean. so iconic. π
π¦ FUNCTION PARAMETERS π¦
userdataβ theuserdatapointer that got passed to the sort function. it just gets handed right back to you, like a little "hey, here's your stuff" moment πaβ a pointer to the first element being compared.bβ a pointer to the second element being compared.
two elements walk into a callbackβ¦ and you're the one who decides who goes first π
β RETURN VALUE β
she returns:
-1ifashould be sorted beforeb1ifbshould be sorted beforea0if they are equal
β οΈ heads up bestie: if two elements are equal, their order in the sorted array is undefined. so don't be out here relying on equal elements keeping their lil original spots β that's not a thing. undefined is undefined, periodt. π
π AVAILABILITY π
this callback has been available since SDL 3.2.0. so if you're on anything olderβ¦ no she's not there yet, sorry babe π§
π SEE ALSO π
go read those next, they're the ones actually calling you. iykyk π₯
and that's the page, bestie!! this one came from Simple Directmedia Layer, SDL 3.4.18, and it's SDL_CompareCallback_r(3type) β mwah, slay, go write a comparator that actually returns the right int πβ¨π
π¦ 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