Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
636 views
in Technique[技术] by (71.8m points)

c - printf and %llx in GCC under Windows 64x

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...