Created
January 14, 2020 16:55
-
-
Save sleepdefic1t/6172e97fa65526a1d6e03f8a57184bb2 to your computer and use it in GitHub Desktop.
Detect Platform Endianness in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment