我经常尝试使用最近的 GCC 构建许多旧的模拟器以及磁盘和磁带归档工具。有些错误很容易修复,但我不是一个很好的程序员。
我明白了:
itstar.c: In function ‘addfiles’:
itstar.c:194:4: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat]
itstar.c:194:4: warning: format ‘%d’ expects argument of type ‘int’, but argument 3 has type ‘long unsigned int’ [-Wformat]
来自这个代码片段:
/* add files to a DUMP tape */
/* output buffer must have been initialized with resetbuf() */
static void addfiles(int argc,char **argv)
{
int c=argc;
char **v=argv;
while(c--) {
addfile(argc,argv,*v++);
}
if(verify)
printf("Approximately %d.%d' of tape used\n",count/bpi/12,
(count*10/bpi/12)%10);
}
第 194 行是倒数第三行,从 printf 开始。
文件是itstar.c,来自tapetools,代码here .
尽管有警告,它仍会生成,但我更想知道如何防止它,
因此结果更有效并且数据损坏的可能性更小。
拜托,我错过了什么,需要改变什么?
提前谢谢你。
最佳答案
使用格式说明符 %lu
而不是 %d
并且您的编译器应该停止提示。
printf("Approximately %lu.%lu' of tape used\n", count/bpi/12, (count*10/bpi/12)%10);
关于c - Re Legacy 代码 : format ‘%d’ expects argument of type ‘int’ , 但参数 3 的类型为 ‘long unsigned int’ [-Wformat],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20590823/