小编Kuz*_*uze的帖子

Re Legacy代码:格式'%d'需要类型为'int'的参数,但参数3的类型为'long unsigned int'[-Wformat]

我经常尝试使用最近的GCC构建大量旧的模拟器和磁盘和磁带归档工具.有些错误很容易解决,但我不是一个程序员.

我明白了:

itstar.c:在函数'addfiles'中:
itstar.c:194:4:警告:格式'%d'需要类型为'int'的参数,但参数2的类型为'long unsigned int'[-
Wformat ] itstar.c :194:4:警告:格式'%d'需要类型为'int'的参数,但参数3的类型为'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);
}
Run Code Online (Sandbox Code Playgroud)

第194行是最后一行,从printf开始.

该文件是itstar.c,来自tapetools,代码在这里.

尽管有警告,它仍会构建,但我更愿意知道如何防止它,
因此结果更有效,并且数据损坏的可能性更小.

拜托,我错过了什么,需要改变?

先感谢您.

c unix printf gcc undefined-behavior

3
推荐指数
2
解决办法
6502
查看次数

标签 统计

c ×1

gcc ×1

printf ×1

undefined-behavior ×1

unix ×1