- #include<stdio.h>
- #include<stdlib.h>
- int main()
- {
- union{
- short s;
- char ch[sizeof(short)];
- }un;
- un.s = 0x0102;
- // printf("%s:",CPU_VERDOR_OS);
- printf("byte order: ");
- if(sizeof(short) == 2)
- {
- if(un.ch[0] == 1 && un.ch[1] == 2)
- printf("big-endian/n");
- else if(un.ch[0] == 2 && un.ch[1] == 1)
- printf("little-endian/n");
- else
- printf("unknown/n");
- }
- else
- printf("sizeof(short) = %d/n",sizeof(short));
- exit(0);
- }
an implementation of detering a platform's byte oerder
最新推荐文章于 2021-03-19 14:53:27 发布