场景:
1.编译器没有显式的指定。
2.需要根据32,64做不同的处理.
方法1:
- #include "stdio.h"
- int main(int argc,char * argv[])
- {
- void* number = 0;
- printf("%d\n",sizeof(&number));
- }
输出8就是64位的,4就是32位的。根据逻辑地址判断。
#include<stdlib.h>
#include <stdio.h>
int main(int argc
{
}
--------------------------------------------------我是分割线 --------------------------------
- #include <stdio.h>
- int main()
- {
- void a = 0x80000000;
- printf("os is %d\n",sizeof(int));
- union ut
- {
- short s;
- char c[2];
- } u;
- if(sizeof(short) == 2)
- {
- u.s = 0x0102;
- if(u.c[0] == 1 && u.c[1] == 2)
- {
- printf("big enidan\n");
- }
- else if(u.c[0] == 2 && u.c[1] == 1)
- {
- printf("little endian.\n");
- }
- return 0;
- }
- return 0;
- }
判断是否c语言:
#ifdef __cplusplus
printf("\n this is c++ language\n");
#else
printf("\nthis is c language\n");
#endif