Ruby 4.1.0dev (2026-10-20 revision 957a081892437c842a94cfd9443b0bdc569d1ef2)
endianness.h
Go to the documentation of this file.
1
4#ifndef PRISM_COMPILER_ENDIANNESS_H
5#define PRISM_COMPILER_ENDIANNESS_H
6
10#if defined(_WIN32) || defined(__LITTLE_ENDIAN__) || (defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__)
11#define PRISM_LITTLE_ENDIAN_COMPTIME
12#endif
13
18#if defined(PRISM_LITTLE_ENDIAN_COMPTIME)
19#define PRISM_LITTLE_ENDIAN_RUNTIME 1
20#elif defined(__BIG_ENDIAN__) || (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
21#define PRISM_LITTLE_ENDIAN_RUNTIME 0
22#else
23#include <stdint.h>
24
25static inline int
27 const union { uint32_t u; uint8_t c[4]; } one = { 1 };
28 return one.c[0];
29}
30
31#define PRISM_LITTLE_ENDIAN_RUNTIME pm_little_endian()
32#endif
33
34#endif
static int pm_little_endian(void)
Detect endianness at compile-time through the use of predefined macros.
Definition endianness.h:26