主题:【贴图】最近看的一些令人蛋疼的好图(四) -- 李根
觉得应该是参数传给printf之前就被做了类型转换成int了(此处应该是把给定参数的最高位重复以达到占满32bit int型),printf里头应该是直接在高位补0?printf这没跟进去看,因为汇编也忘的差不多了,不过重复了好几遍,结果都是稳定的,应该printf内部从int到long int不是越界读的结果。
gcc 4.2.4 x86_64-linux-gnu
int main () {
/*
int i=1;
int j=(1<<31)+255;
char *c_ip = &j;
printf("int len is %d\n",sizeof(i));
printf("long int len is %d\n",sizeof(j));
printf("int pointer len is %d\n",sizeof(&i));
printf("int is %x\n",j);
printf("long int j is %llx\n",j);
printf("long int char pointer is %llx\n",*c_ip);*/
int a=-1;
printf("long int a is %llx\n",a);
int b=255;
printf("long int b is %llx\n",b);
char c=128;
printf("long int c is %llx\n",c);
char d=127;
printf("long int d is %llx\n",d);
char f=128;
printf("long int f is %llx\n",(int)f);
char g=127;
printf("long int f is %llx\n",(int)g);
printf("long int -1 is %llx\n",(long int)-1);
return 0;
}
output:
long int a is ffffffff
long int b is ff
long int c is ffffff80
long int d is 7f
long int f is ffffff80
long int f is 7f
long int -1 is ffffffffffffffff
- 相关回复 上下关系6
🙂你是对的 发了胖的罗密欧 字120 2012-03-05 15:01:12
🙂恩,应该是printf自己做了类型转换了 szxy 字0 2012-03-05 21:31:31
🙂printf()用的是变长参数列表 1 发了胖的罗密欧 字186 2012-03-06 05:22:25
🙂写了个短看了下
😄花妓者们,花公知们,为他们凉掉的洗脚水干杯~~~ 索罗门 字0 2012-03-02 22:55:07
🙂这玩意儿太好看了 cmosplay 字16 2012-03-02 22:42:38