//大小端判断
#include <iostream>

bool endian_big_little_pointer();
bool endian_big_little_union();

int main()
{
    if(endian_big_little_pointer() && endian_big_little_union())
        std::cout<<"big endian"<<std::endl;
    else
        std::cout<<"little endian"<<std::endl;
}
//利用位操作判断大小端
bool endian_big_little_pointer(){
    int V = 0x0D0C;
    char c = *(char*)(&V);
    if(c == 0x0D)
        return true;
    else
        return false;
}
//利用C语言的union结构判断大小端
bool endian_big_little_union(){
    union endian{
        int a;
        char b;
    }flag;
    
    flag.a = 1;
    return (flag.b != 1);
}
posted on 2012-08-13 10:25  fisher2012  阅读(146)  评论(0编辑  收藏  举报