|
各位高手:小弟写了一段很小的程序测试用,代码如下:
#include <stdio.h>
#include <string.h>
main()
{
unsigned long long mask;
unsigned long long val;
char c[4];
mask = 255;
val = 3;
printf("Output use lld : val = %lld,mask = %lld\n",val,mask);
printf("Output use 2x : val = %2x,mask = %2x\n",val,mask);
printf("Output use 2x : mask = %2x,val = %2x\n",mask,val);
printf("mask = %2x\n",mask);
printf("val = %2x\n",val);
printf("%2x\n",(mask & val));
memset(c,0,4);
sprintf(c,"%2x",(mask & val));
printf("%s\n",c);
}
x86平台下,gcc编译运行,结果如下:
Output use lld : val = 3,mask = 255
Output use 2x : val = 3,mask = 0
Output use 2x : mask = ff,val = 0
mask = ff
val = 3
3
3
PowerPC平台下,gcc编译运行,结果如下:
Output use lld : val = 3,mask = 255
Output use 2x : val = 30013000,mask = 0
Output use 2x : mask = 30013000,val = 0
mask = 30013000
val = 30013000
30013000
0
均不能完全正确。
不知什么原因,但是如果使用long或者int代替long long 定义,就没有问题。
各位高手指教一二啊!
小弟谢了,先! |
|