SDL_SwapFloat(3)

✨ SDL_SwapFloat β€” the byte-flipping glow-up ✨

okay bestie, welcome to SDL_SwapFloat(3), a lil page from the SDL3 FUNCTIONS collection πŸ’–. She's tiny, she's forced-inline, and she is obsessed with flipping your bytes. let's get into it πŸ¦‹


🌸 NAME 🌸

SDL_SwapFloat β€” Byte-swap a floating point number. that's it. that's the whole job. she takes a float and she flips the endianness, no cap πŸ’…


✨ SYNOPSIS ✨

#include <SDL3/SDL_endian.h>

SDL_FORCE_INLINE float SDL_SwapFloat(float x);

look at her. header-only. inline. cute. πŸŽ€


πŸ’œ DESCRIPTION πŸ’œ

so here's the tea, bestie: this function will always byte-swap the value. like, always. it does not care whether the value is currently in the native byteorder of the system or not β€” it's gonna swap it regardless. she doesn't check, she doesn't ask, she just swaps 🫢

which means... most of the time, that is NOT what you want. in most cases you should be using SDL_SwapFloatLE or SDL_SwapFloatBE instead, because those ones actually know what they're doing and will do the right thing depending on the target endianness. this one is the raw, unfiltered, no-thoughts-just-swaps version. iykyk πŸ’€

also important, and not me being dramatic: this is a forced-inline function in a header, and it is not a public API function available in the SDL library. translation? the code is embedded directly in the 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 binary, she lives in your code now 🏠✨

πŸ“ FUNCTION PARAMETERS πŸ“

  • x β€” the value to byte-swap. that's the one. the only one. hand her over 🌈

πŸ’« RETURN VALUE πŸ’«

Returns x, but with its bytes in the opposite endian order. same number, same vibes, flipped bytes. she ate πŸ’…


🧚 THREAD SAFETY 🧚

It is safe to call this function from any thread. any thread, any time, any vibe. she's not out here causing problems πŸ”₯


πŸ‘‘ AVAILABILITY πŸ‘‘

This function is available since SDL 3.2.0. so if you're on something older... girl. upgrade πŸ’€


okay that's the whole page, you're officially educated πŸ’– huge thank you to Simple Directmedia Layer for this one β€” this is SDL 3.4.18, and this lil SDL_SwapFloat(3) page is dated right along with it. go forth and byte-swap responsibly, bestie πŸ¦‹βœ¨πŸŽ€

πŸ“¦ where this page comes from