首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >mingw环境中64位字符串格式化程序的警告

mingw环境中64位字符串格式化程序的警告
EN

Stack Overflow用户
提问于 2018-09-06 10:25:19
回答 1查看 544关注 0票数 0

对于最近版本的mingw-w64,避免对64位printf/scanf参数发出警告的正确方法是什么?

我知道很多标准库函数都依赖于microsoft运行时,而且这些函数与C99标准不兼容。

旧的答案说要使用%I64d,但是由于C99标准是%lld,无论如何,如果我使用-Wall -pedantic编译,就会收到语法的警告,下面是一个小示例:

代码语言:javascript
运行
复制
#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):

代码语言:javascript
运行
复制
x86_64-w64-mingw32-gcc -o test.exe test.c -Wall -pedantic

它发出以下警告:

代码语言:javascript
运行
复制
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)。

EN

回答 1

Stack Overflow用户

发布于 2018-09-06 10:30:05

如果您想要编译到Microsoft平台,您就不能对遵循该标准感到浮躁。拥抱、扩展(和熄灭)!删除-pedantic或获得正确的C99/C11/C17实现。

C89不支持%lld。如果碰巧将支持-Wformat作为扩展的库作为目标,则需要禁用它。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52201952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档