sleepdefic1t
1/14/2020 - 4:55 PM

Detect Platform Endianness in C

Detect Platform Endianness in C


#ifndef ENDIAN_H
#define ENDIAN_H

#include <stdint.h>

int isBigEndian() {
    union {
        uint32_t i;
        char c[4];
    } e = { 0x01000000 };

    return e.c[0];
}

#endif  // #define ENDIAN_H