判断CPU大小端模式

/*
 * 判断CPU大小端模式
 * CPU: Intel (R) CPU T2050 @ 1.60GHz
 * OS: Windows XP
 * Compiler: Visual C++ 2008 Express Edition
 * Programming Language: C
 * Time: 19:45 2009-12-9
 */
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int main(void)
{
     unsigned short int i = (unsigned short int)0XFF01;
     assert(sizeof(short int) >= 2);  // 判断具体编译器设定的short int类型的长度
     if (*((char *)&i) == 1)
         printf("Little-Endian: 数据的低字节部分存储在内存的低地址处\n");
     else
         printf("Big-Endian: 数据的低字节部分存储在内存的高地址处\n");
     system("pause");
     return 0;
}

你可能感兴趣的:(cpu,职场,休闲)