测试大小端方法

在cu上看到一种测试大小端的方法,且记下来:

内核中抠出来的一个测试大小端的程序,非常好,而且简练。内核的技巧真是无处不再阿.
/*
*author:qqbsd
*email:qqbsd.zhou@gmail.com
*/
#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 == 'g')
printf("big ednian.\n");
else
printf("error. c = %c \n", c);
return 0;

 

 http://bbs.chinaunix.net/thread-1965448-1-1.html

posted @ 2012-03-12 09:40    阅读(642)  评论(0编辑  收藏  举报