对于最近版本的mingw-w64,避免对64位printf/scanf参数发出警告的正确方法是什么?
我知道很多标准库函数都依赖于microsoft运行时,而且这些函数与C99标准不兼容。
旧的答案说要使用%I64d,但是由于C99标准是%lld,无论如何,如果我使用-Wall -pedantic编译,就会收到双语法的警告,下面是一个小示例:
#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)。
发布于 2018-09-06 10:30:05
如果您想要编译到Microsoft平台,您就不能对遵循该标准感到浮躁。拥抱、扩展(和熄灭)!删除-pedantic或获得正确的C99/C11/C17实现。
C89不支持%lld。如果碰巧将支持-Wformat作为扩展的库作为目标,则需要禁用它。
https://stackoverflow.com/questions/52201952
复制相似问题