Endian Test

#include <stdio.h>
static union {char c[4];unsigned long l;} endian_test={{'l','?','?','b'}};
#define ENDIANNESS ((char)endian_test.l)
int checkCPU()
{
        {
                union w{
                        int a;
                        char b;
                }c;
                c.a=1;
                return (c.b==1);
        }
}
int main(int argc, char *argv[])
{
        printf("%s\n", checkCPU()?"Little endian":"Big endian");
        printf("%s\n", ENDIANNESS == 'l'?"Little endian":"Big endian");
        return 0;
}
 

你可能感兴趣的:(test)