判断网络字节序
- #include <stdio.h>
- typedef union{
- unsigned short value;
- unsigned char bytes[2];
- }Test;
- int main(void)
- {
- Test test_value;
- test_value.value = 0x1234;
- if(test_value.bytes[0] == 0x12 && test_value.bytes[1] == 0x34)
- printf("big ending");
- else if(test_value.bytes[0] == 0x34 && test_value.bytes[1] == 0x12)
- printf("little ending");
- else
- printf("use test_value error");
- return 0;
- }
判断操作系统32、64
判断指针
1 #include<stdio.h>
2 int main()
3 {
4 int n=sizeof(char*);
5 if(n==4)
6 printf("%d\n",n);
7 if(n==8)
8 printf("%d\n",n);
9 }
~
~
~
~