大小端测试用例 (C语言)

#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语言))