请问如何编程判断是16位机还是32位机,不能用sizeof

blandyzld 2008-07-07 02:39:12
请问如何编程判断是16位机还是32位机,不能用sizeof
...全文
160 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
fairuyy 2010-08-06
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 k2eats 的回复:]
C/C++ code

#include <stdio.h>
int main()
{
int a =1;
if(a<<15 >0)
printf("32 bit machine!\n");
else
printf("16 bit machine!\n");
}
[/Quote]

如果要同时判断是4位,16位,32位,64位时就不好用了
Jerrylearnc 2008-07-07
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 Jerrylearnc 的回复:]
引用 2 楼 hailongchang 的回复:
int a = 5;
int *p = &a;

printf("%d",p);


这个根据什么作出判断
谢谢
非常感谢
[/Quote]
blandyzld 2008-07-07
  • 打赏
  • 举报
回复
谢谢各位大侠了!
Jerrylearnc 2008-07-07
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 hailongchang 的回复:]
int a = 5;
int *p = &a;

printf("%d",p);
[/Quote]

这个根据什么作出判断
谢谢
非常感谢
Andrwyw 2008-07-07
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 k2eats 的回复:]
C/C++ code
#include <stdio.h>
int main()
{
int a =1;
if(a<<15 >0)
printf("32 bit machine!\n");
else
printf("16 bit machine!\n");
}
[/Quote]
aozhi 2008-07-07
  • 打赏
  • 举报
回复
这样比较安全。

#include <stdio.h>
int main ()
{
int i[2];
printf("%d bit machine.\n",(int)((void*)(i+1)-(void*)(i))*8);
getch();
}
aozhi 2008-07-07
  • 打赏
  • 举报
回复

#include <stdio.h>
int main ()
{
int *i;
printf("%d bit machine.\n",(int)((void*)(i+1)-(void*)(i))*8);
getch();
}
zjw6861982 2008-07-07
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 k2eats 的回复:]
C/C++ code#include<stdio.h>intmain()
{inta=1;if(a<<15>0)
printf("32 bit machine!\n");elseprintf("16 bit machine!\n");
}
[/Quote]
^_^
K行天下 2008-07-07
  • 打赏
  • 举报
回复

#include <stdio.h>
int main()
{
int a =1;
if(a<<15 >0)
printf("32 bit machine!\n");
else
printf("16 bit machine!\n");
}

hailongchang 2008-07-07
  • 打赏
  • 举报
回复
int a = 5;
int *p = &a;

printf("%d",p);
yyyapple 2008-07-07
  • 打赏
  • 举报
回复
int* p = 0 ;
p++;
printf("%d",((unsigned char*)p-(unsigned char*)0 )*8 );

69,336

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧