int square(int n)//计算平方的函数,是记录下有符号数和longlong类型运算情况, { ?? ?int k=0; ?? ?u8 *p; ?? ?long long a=0; ?? ?a= (long long)n*n; ?? ?p=(u8*)&a; ?? ?printf("sizeof(int):%d ?sizeof(long):%d sizeof(long long):%d ?n=0x%x n=%d\r\n",sizeof(int),sizeof(long),sizeof(long long),n,n); ?? ?while(1) ?? ?{ ?? ??? ?if(k==n*n) ?? ??? ?{?? ??? ? ?? ??? ??? ?printf("k=%x\t n*n=%X ?(long long)n*n=%llx (long long)a=%lld \r\n",k,n*n,(long long)n*n,a); ?? ??? ??? ?printf("p[0-7]:%02x%02x%02x%02x%02x%02x%02x%02x\r\n",p[0],p[1],p[2],p[3],p[4],p[5],p[6],p[7]); ?? ??? ??? ?return k; ?? ??? ?} ?? ??? ?k++; ?? ?} }
void s_test() { ?? ? ?? ?square(8); ?? ?square(0x7FFFFFFF); ?? ?square(0x80000030); ?? ?square(0xFFFFFFFF);
}
运算结果:?linux下的验证
单片机验证:由于%llx不能输出,因此部分结果不可见
?
|