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 forSDL_Swap16when you actually mean "swap to little endian" or "swap to big endian", that's your sign to grabSDL_Swap16LE/SDL_Swap16BEinstead. 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
- 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