Skip to content

Instantly share code, notes, and snippets.

@icecoobe
Created August 23, 2017 07:12
Show Gist options
  • Save icecoobe/941382634d8cac69237e31e3e6999f9f to your computer and use it in GitHub Desktop.
Save icecoobe/941382634d8cac69237e31e3e6999f9f to your computer and use it in GitHub Desktop.
check whether CPU is little-endian
#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