#include <stdio.h>
#define BIG_ENDIAN 1
#define LITTLE_ENDIAN 0
int getEndianness()
{
int a = 0x12345678;
char *p;
p = (char *)(&a);
if(0x78 == *p)
{
return LITTLE_ENDIAN;
}
return BIG_ENDIAN;
}
int main()
{
int rv = getEndianness();
if(LITTLE_ENDIAN == rv)
{
printf("little endian\n");
}
else
{
printf("big endian\n");
}
return 0;
}