【发布时间】:2009-11-17 13:26:08
【问题描述】:
struct DummyStruct{
unsigned long long std;
int type;
};
DummyStruct d;
d.std = 100;
d.type = 10;
/// buggy printf, unsigned long long to int conversion is buggy.
printf("%d,%d\n",d.std, d.type); // OUTPUT: 0,100
printf("%d,%d\n", d.type, d.std); // OUTPUT: 10,100
printf("%lld,%d\n",d.std, d.type); // OUTPUT: 100,10
请告诉我为什么在 printf 中没有正确处理 unsigned long long 到 int 的转换。我正在使用 glibc。
这是 printf 中的错误吗?
为什么 printf 不做内部类型转换?
【问题讨论】:
-
谢谢 Mykola,现在我已经纠正了我的错误。
-
大多数编译器都会对您犯的错误发出警告 - 您是否忽略了它?或者你没有打开警告?他们在那里是有原因的。