在最新版本的mingw-w64上,避免64位printf / scanf参数警告的正确方法是什么?
我知道mingw-w64依赖于许多标准库函数的microsoft运行时,并且这些函数与C99标准不兼容。
旧答案说使用%I64d,但由于C99标准是%lld,无论如何,如果我使用-Wall -pedantic进行编译,我会收到BOTH语法的警告,这里有一个小例子:
#include <stdio.h>
int main(void)
{
long long test;
scanf("%I64d", &test);
scanf("%lld", &test);
}
用gcc编译它(我的版本是mingw-w64 5.0.4,gcc 8.2.0):
x86_64-w64-mingw32-gcc -o test.exe test.c -Wall -pedantic
它给出了以下警告:
dev:tmp dev$ x86_64-w64-mingw32-gcc -o test.exe test.c -Wall -pedantic
test.c: In function ‘main’:
test.c:6:11: warning: ISO C does not support the ‘I64’ ms_scanf length modifier [-Wformat=]
scanf("%I64d", &test);
^~~~~~~
test.c:6:11: warning: ISO C does not support the ‘I64’ ms_scanf length modifier [-Wformat=]
test.c:7:14: warning: unknown conversion type character ‘l’ in format [-Wformat=]
scanf("%lld", &test);
^
test.c:7:11: warning: too many arguments for format [-Wformat-extra-args]
scanf("%lld", &test);
^~~~~~
test.c:7:14: warning: unknown conversion type character ‘l’ in format [-Wformat=]
scanf("%lld", &test);
^
test.c:7:11: warning: too many arguments for format [-Wformat-extra-args]
scanf("%lld", &test);
^~~~~~
删除-Wall删除了两个警告,没有-pedantic我可以编译而没有警告第6行(%I64d)但不是第7行(%lld)。
如果你想编译到微软平台,你不能对遵循标准迂腐。拥抱,延伸(和熄灭)!删除-pedantic
或获得适当的C99 / C11 / C17实现。
C89不支持%lld
。如果您碰巧将支持它的库作为扩展名,那么您似乎需要禁用-Wformat
。