SDL_Swap16LE(3)

πŸ’– SDL_Swap16LE πŸ’–

okay bestie, welcome to the SDL3 FUNCTIONS corner of the manual, where today's main character is SDL_Swap16LE β€” the little macro that flips a 16-bit value from littleendian into whatever byte order your machine actually speaks. she's small, she's precise, she's iconic. let's get into it πŸŽ€


✨ NAME ✨

SDL_Swap16LE β€” swap a 16-bit value from littleendian to native byte order. that's it, that's the job, and she does it flawlessly πŸ’…


🌸 SYNOPSIS 🌸

#include <SDL3/SDL_endian.h>

#define SDL_Swap16LE(x) SwapOnlyIfNecessary(x)

so yeah, it's a macro, not a function. no cap. she expands into SwapOnlyIfNecessary(x) and lets the preprocessor handle the rest πŸ¦‹


πŸ’œ DESCRIPTION πŸ’œ

okay so here's the vibe: if this is running on a littleendian system, then x is returned unchanged. like, no swap needed, nothing to do, she just hands it right back to you. periodt ✨

and here's the part that's lowkey genius β€” this macro never references x more than once, which avoids side effects. so if you were ever worried about your expression getting evaluated twice behind your back… not today, bestie πŸ™ˆ


πŸŽ€ MACRO PARAMETERS πŸŽ€

  • x β€” the value to swap, in littleendian byte order. give her the 16-bit cutie in LE, she'll give you back native πŸ’–

🫢 RETURN VALUE 🫢

Returns x in native byte order. simple, clean, no drama 🌈


πŸ”₯ THREAD SAFETY πŸ”₯

It is safe to call this macro from any thread. yes bestie, any thread β€” she's got no shared state, no secrets, no ✨complicated✨ past. go wild, she can handle it πŸ‘‘


⭐ AVAILABILITY ⭐

This macro is available since SDL 3.2.0. so if you're on something older… upgrade, babe 😭


🧚 tiny reminder: everything above is literally exactly what she does. don't get creative with the byte order and then blame the macro. iykyk πŸ’€

and that's the whole page, bestie! this little love letter came to you from Simple Directmedia Layer, rocking version SDL 3.4.18, and honestly? she ate. go forth and swap responsibly πŸ’…πŸ’–βœ¨

πŸ“¦ where this page comes from