实现了2个 函数,判断操作系统的位数和主机字节序
#include <stdio.h>
int show_sys_bit(void);
int show_sys_endian(void);
int main(int argc,char * argv[])
{
show_sys_bit();
show_sys_endian();
return 0;
}
/*
获取操作系统的位数
返回的为实际位数
*/
int show_sys_bit(void)
{
unsigned int SYS_SIZE = sizeof(void *);
if ( 4 == SYS_SIZE )
printf("This system is 32 bit/r/n");
else if ( 8 == SYS_SIZE )
printf("This system is 64 bit/r/n");
return SYS_SIZE*8;
}
/*
获取主机字节序
返回0 为小端
否则 为大端
*/
int show_sys_endian(void)
{
union sys_endian
{
unsigned short num;
unsigned char a[2];
}sys;
sys.num = 1;
if ( 1 == sys.a[0] )
printf("The host is little_ending/r/n");
else
printf("The host is big_ending/r/n");
return sys.a[0];
}