SDL_Swap16(3)

πŸ’… SDL_Swap16

okay so bestie, welcome to the SDL3 FUNCTIONS corner of the manual, and today's main character is SDL_Swap16. yes she's tiny. yes she's a header inline. yes she still ate. let's go πŸŽ€

✨ NAME ✨

SDL_Swap16 β€” byte-swap an unsigned 16-bit number. that's it. that's the whole job. iconic behavior honestly πŸ’–


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_endian.h>

SDL_FORCE_INLINE Uint16 SDL_Swap16(Uint16 x);

πŸ¦‹ DESCRIPTION πŸ¦‹

so the way this works: it will always byte-swap the value, no matter what. doesn't matter if it's currently in the native byteorder of the system or not β€” she does not care, she does not check, she just flips those bytes. periodt. πŸ’…

which is exactly why you should be using SDL_Swap16LE or SDL_Swap16BE instead, in most cases. those two actually know what they're doing. SDL_Swap16 is the raw unhinged version. use her with intention bestie πŸ™ˆ

also, big note: this is a forced-inline function in a header, not a public API function hanging out in the SDL library. which is to say β€” the code gets embedded right into your calling program, and the linker and dynamic loader will not be able to find this function inside SDL itself. so don't go looking for her in the library, she lives in your binary now. she moved in. 🏠✨


🧚 FUNCTION PARAMETERS 🧚

  • x β€” the value to byte-swap. that's the one. the little guy. the victim of the flip. πŸ“

⭐ RETURN VALUE ⭐

returns x, with its bytes in the opposite endian order. same number, same type, just... rearranged. glow-up via permutation. πŸ”₯

πŸ’œ THREAD SAFETY πŸ’œ

it is safe to call this function from any thread. no drama, no locks, no fights in the group chat. everyone can call her at once. 🫢

πŸ‘‘ AVAILABILITY πŸ‘‘

this function is available since SDL 3.2.0. so if you're on something older... no she's not there yet, sorry bestie 😭


lowkey a whole vibe check: if you find yourself reaching for SDL_Swap16 when you actually mean "swap to little endian" or "swap to big endian", that's your sign to grab SDL_Swap16LE / SDL_Swap16BE instead. fr fr. 🌈

and that's the page!! brought to you by Simple Directmedia Layer, version SDL 3.4.18 β€” mwah, take care of her, she's doing her best πŸ’–βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from