SDL 3.0
SDL_endian.h File Reference
+ Include dependency graph for SDL_endian.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

The two types of endianness

#define SDL_LIL_ENDIAN   1234
 
#define SDL_BIG_ENDIAN   4321
 
#define SDL_BYTEORDER   SDL_LIL_ENDIAN
 
#define SDL_FLOATWORDORDER   SDL_BYTEORDER
 
#define HAS_BUILTIN_BSWAP16   0
 
#define HAS_BUILTIN_BSWAP32   0
 
#define HAS_BUILTIN_BSWAP64   0
 
#define HAS_BROKEN_BSWAP   0
 
#define SDL_SwapLE16(x)   (x)
 
#define SDL_SwapLE32(x)   (x)
 
#define SDL_SwapLE64(x)   (x)
 
#define SDL_SwapFloatLE(x)   (x)
 
#define SDL_SwapBE16(x)   SDL_Swap16(x)
 
#define SDL_SwapBE32(x)   SDL_Swap32(x)
 
#define SDL_SwapBE64(x)   SDL_Swap64(x)
 
#define SDL_SwapFloatBE(x)   SDL_SwapFloat(x)
 
SDL_FORCE_INLINE Uint16 SDL_Swap16 (Uint16 x)
 
SDL_FORCE_INLINE Uint32 SDL_Swap32 (Uint32 x)
 
SDL_FORCE_INLINE Uint64 SDL_Swap64 (Uint64 x)
 
SDL_FORCE_INLINE float SDL_SwapFloat (float x)
 

Detailed Description

Functions for reading and writing endian-specific values

Definition in file SDL_endian.h.

Macro Definition Documentation

◆ HAS_BROKEN_BSWAP

#define HAS_BROKEN_BSWAP   0

Definition at line 138 of file SDL_endian.h.

◆ HAS_BUILTIN_BSWAP16

#define HAS_BUILTIN_BSWAP16   0

Definition at line 135 of file SDL_endian.h.

◆ HAS_BUILTIN_BSWAP32

#define HAS_BUILTIN_BSWAP32   0

Definition at line 136 of file SDL_endian.h.

◆ HAS_BUILTIN_BSWAP64

#define HAS_BUILTIN_BSWAP64   0

Definition at line 137 of file SDL_endian.h.

◆ SDL_BIG_ENDIAN

#define SDL_BIG_ENDIAN   4321

Definition at line 55 of file SDL_endian.h.

◆ SDL_BYTEORDER

#define SDL_BYTEORDER   SDL_LIL_ENDIAN

Definition at line 85 of file SDL_endian.h.

◆ SDL_FLOATWORDORDER

#define SDL_FLOATWORDORDER   SDL_BYTEORDER

Definition at line 108 of file SDL_endian.h.

◆ SDL_LIL_ENDIAN

#define SDL_LIL_ENDIAN   1234

Definition at line 54 of file SDL_endian.h.

◆ SDL_SwapBE16

#define SDL_SwapBE16 (   x)    SDL_Swap16(x)

Definition at line 505 of file SDL_endian.h.

◆ SDL_SwapBE32

#define SDL_SwapBE32 (   x)    SDL_Swap32(x)

Definition at line 506 of file SDL_endian.h.

◆ SDL_SwapBE64

#define SDL_SwapBE64 (   x)    SDL_Swap64(x)

Definition at line 507 of file SDL_endian.h.

◆ SDL_SwapFloatBE

#define SDL_SwapFloatBE (   x)    SDL_SwapFloat(x)

Definition at line 508 of file SDL_endian.h.

◆ SDL_SwapFloatLE

#define SDL_SwapFloatLE (   x)    (x)

Definition at line 504 of file SDL_endian.h.

◆ SDL_SwapLE16

#define SDL_SwapLE16 (   x)    (x)

Definition at line 501 of file SDL_endian.h.

◆ SDL_SwapLE32

#define SDL_SwapLE32 (   x)    (x)

Definition at line 502 of file SDL_endian.h.

◆ SDL_SwapLE64

#define SDL_SwapLE64 (   x)    (x)

Definition at line 503 of file SDL_endian.h.

Function Documentation

◆ SDL_Swap16()

SDL_FORCE_INLINE Uint16 SDL_Swap16 ( Uint16  x)

Definition at line 180 of file SDL_endian.h.

181{
182 return SDL_static_cast(Uint16, ((x << 8) | (x >> 8)));
183}
uint16_t Uint16
Definition SDL_stdinc.h:206
#define SDL_static_cast(type, expression)
Definition SDL_stdinc.h:127

References SDL_static_cast.

◆ SDL_Swap32()

SDL_FORCE_INLINE Uint32 SDL_Swap32 ( Uint32  x)

Definition at line 227 of file SDL_endian.h.

228{
229 return SDL_static_cast(Uint32, ((x << 24) | ((x << 8) & 0x00FF0000) |
230 ((x >> 8) & 0x0000FF00) | (x >> 24)));
231}
uint32_t Uint32
Definition SDL_stdinc.h:224

References SDL_static_cast.

Referenced by SDL_Swap64(), and SDL_SwapFloat().

◆ SDL_Swap64()

SDL_FORCE_INLINE Uint64 SDL_Swap64 ( Uint64  x)

Definition at line 270 of file SDL_endian.h.

271{
272 Uint32 hi, lo;
273
274 /* Separate into high and low 32-bit values and swap them */
275 lo = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
276 x >>= 32;
277 hi = SDL_static_cast(Uint32, x & 0xFFFFFFFF);
278 x = SDL_Swap32(lo);
279 x <<= 32;
280 x |= SDL_Swap32(hi);
281 return (x);
282}
SDL_FORCE_INLINE Uint32 SDL_Swap32(Uint32 x)
Definition SDL_endian.h:227

References SDL_static_cast, and SDL_Swap32().

◆ SDL_SwapFloat()

SDL_FORCE_INLINE float SDL_SwapFloat ( float  x)

Byte-swap a floating point number.

This will always byte-swap the value, whether it's currently in the native byteorder of the system or not. You should use SDL_SwapFloatLE or SDL_SwapFloatBE instead, in most cases.

Note that this is a forced-inline function in a header, and 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).

Parameters
xthe value to byte-swap.
Returns
x, with its bytes in the opposite endian order.

\threadsafety It is safe to call this function from any thread.

Since
This function is available since SDL 3.0.0.

Definition at line 305 of file SDL_endian.h.

306{
307 union {
308 float f;
309 Uint32 ui32;
310 } swapper;
311 swapper.f = x;
312 swapper.ui32 = SDL_Swap32(swapper.ui32);
313 return swapper.f;
314}

References SDL_Swap32().