#include <stdio.h>
static union { char c[4]; unsigned long l; } endian_test = { {'l','?','?','b'} };
#define ENDIANNESS ((char)endian_test.l)
int main(void)
{
char c = ENDIANNESS;
if(c == 'l')
printf("little endian.\n");
else if(c == 'b')
printf("big ednian.\n");
else
printf("error. c = %c \n", c);
return 0;
} 大小端测试用例 (C语言)
最新推荐文章于 2022-05-04 20:55:03 发布
本文提供了一个简单的 C 语言程序来检测计算机系统的字节序。通过定义一个联合体并初始化特定的字节序列,程序能够判断系统是使用小端字节序还是大端字节序。
1990

被折叠的 条评论
为什么被折叠?



