SDL_Swap32(3)

πŸ’… SDL_Swap32 πŸ’…

okay bestie, welcome to SDL_Swap32, straight outta the SDL3 FUNCTIONS lineup ✨ this one's short and sweet and honestly kind of iconic for it.


🌸 NAME 🌸

SDL_Swap32 β€” Byte-swap an unsigned 32-bit number. that's it. that's the whole job. she flips your bytes and she does NOT elaborate πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

#include <SDL3/SDL_endian.h>

SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x);

✨ DESCRIPTION ✨

okay so listen. this function will always byte-swap the value, no cap β€” whether it's currently in the native byteorder of the system or not. like, it does not check. it does not care. it just swaps. periodt.

which is exactly why, in most cases, you should be using SDL_Swap32LE or SDL_Swap32BE instead. those two are the responsible ones who actually look before they leap 🫢

πŸ’€ important lore alert: this is a forced-inline function in a header, NOT a public API function available in the SDL library. which is to say β€” the code is embedded in the calling program, and the linker and dynamic loader will not be able to find this function inside SDL itself. she lives in your binary now. no takebacks πŸ™ˆ

🧚 FUNCTION PARAMETERS 🧚

  • x β€” the value to byte-swap. hand her your lil 32-bit number and she'll hand it back flipped πŸ’–

⭐ RETURN VALUE ⭐

Returns x, with its bytes in the opposite endian order. same number, new arrangement, main character energy πŸ‘‘


🌈 THREAD SAFETY 🌈

It is safe to call this function from any thread. go wild, gorl, every thread can have a turn πŸ’œ


πŸ¦‹ AVAILABILITY πŸ¦‹

This function is available since SDL 3.2.0. if you're on anything older, sorry bestie, she hasn't been born yet 😭


okay that's the whole page, love that for us πŸŽ€ mwah πŸ’‹

β€” Simple Directmedia Layer, SDL 3.4.18, and yes this was SDL_Swap32(3) the whole time. stream it, byte-swap responsibly, bye bestie 🫢✨

πŸ“¦ where this page comes from