在Windows 64x下的GCC中的printf和%llx [英] printf and %llx in GCC under Windows 64x

查看:130
本文介绍了在Windows 64x下的GCC中的printf和%llx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的程序中摆脱伪造的警告。在windows 64下(linux下没有这样的警告):

  printf(%llu,UINT64_MAX); 

会产生以下警告:

<$ p $警告:格式为[-Wformat] |的未知转换类型字符'l'

输出看起来是正确的,警告不应该在那里。我能找到的最相关的gcc相关帖子是2008年以来的这个bug报告 http: //gcc.gnu.org/bugzilla/show_bug.cgi?id=37768



如果我根据这个理解正确的话,这个警告源于事实gcc调用MSVC printf,它不符合C99,并且无法理解printf中的无符号long long格式。建议的解决方案从同一页面使用名为gnu_printf的东西。我试图谷歌,但我没有找到一个头包括。

所以问题是这应该如何处理,以便携?我只是想以正确和非马虎的方式摆脱警告。

解决方案

因为我猜你可能已经知道,从 http://comments.gmane.org/gmane.comp.gnu.mingw.w64.general/4670 (注意:死链接;请参阅互联网档案馆的副本),


问题在于formatter-width说明符%ll 不支持
所有msvcrt-DLL版本,因此gcc会警告它的使用。以
msvcrt向后兼容的方式在格式化程序中指定64位整数标量宽度的
变量使用%I64



I am trying to get rid of a bogus warning in my program. Under windows 64 (under linux there is no such warning) this statement:

printf("%llu",UINT64_MAX);

generates the following warning:

warning: unknown conversion type character 'l' in format [-Wformat]|

The output appears to be correct and the warning should not be there. The most relevant gcc related post I can find is this bug report back from 2008 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37768

If I understand correctly according to that, this warning stems from the fact that under the hood gcc calls MSVC printf which is not C99 compliant and can't understand the unsigned long long format in printf. From the same page the suggested solution is to use something called gnu_printf. I tried to google that but I did not find a header to include.

So the question is how should this be handled in order to be portable? I just want to get rid of the warning in a correct and non-sloppy way.

解决方案

As I'm guessing you probably already know, from http://comments.gmane.org/gmane.comp.gnu.mingw.w64.general/4670 (note: dead link; see the Internet Archive's copy),

the issue is that formatter-width specifier %ll isn't supported for all msvcrt-DLL versions, therefore gcc warns about its use. The variant for specifying 64-bit integer-scalar-width in formatter for msvcrt in a backward-compatible way is by using %I64.

这篇关于在Windows 64x下的GCC中的printf和%llx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆