Created
August 23, 2017 07:12
-
-
Save icecoobe/941382634d8cac69237e31e3e6999f9f to your computer and use it in GitHub Desktop.
check whether CPU is little-endian
This file contains 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
#include <stdio.h> | |
#include <stdlib.h> | |
int is_little_endian(void) | |
{ | |
union w | |
{ | |
int a; | |
char b; | |
} c; | |
c.a = 1; | |
return (c.b == 1); | |
} | |
int main(void) | |
{ | |
int ret = is_little_endian(); | |
printf("%d\n", ret); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment