Silence half of warnings in MinGW
PATCH 1/1 Silence half of warnings in MinGW
This patch suppresses a lot of mingw warnings like
qemu-img.c:288: warning: format '%I64u' expects type 'unsigned int', but argument 2 has type 'uint64_t'
configure (working copy) renamed from configure (revision 6466) +1 -0
@@ -573,6 +573,7 @@ if test "$mingw32" = "yes" ; then linux="no" EXESUF=".exe" + CFLAGS+=" -Wno-format" oss="no" linux_user="no" bsd_user="no"
Quoted 2 lines · Consul
This patch suppresses a lot of mingw warnings like
qemu-img.c:288: warning: format '%I64u' expects type 'unsigned int', but argument 2 has type 'uint64_t'
I'd rather see the warning fixed (by switching to PRIu64) than to have the warnings disabled.
Regards,
Anthony Liguori
Quoted 15 lines
Signed-off-by Alex Ivanov <[email protected]>configure (working copy) renamed from configure (revision 6466) +1
-0@@ -573,6 +573,7 @@ if test "$mingw32" = "yes" ; then linux="no" EXESUF=".exe" + CFLAGS+=" -Wno-format" oss="no" linux_user="no" bsd_user="no"
[Qemu-devel] Mingw GCC not recognising printf format "%I64u"
Quoted 7 lines · Anthony Liguori
Quoted 3 lines · Consul
This patch suppresses a lot of mingw warnings like qemu-img.c:288: warning: format '%I64u' expects type 'unsigned int', but argument 2 has type '
uint64_t'I'd rather see the warning fixed (by switching to PRIu64) than to have the warnings disabled.
Since that's in code for Windows, I'd rather see mingw's GCC fixed to recognise %I64u, since that's fine Windows code.
Cc'd to mingw-users list for that reason.
-- Jamie
Re: [Qemu-devel] Mingw GCC not recognising printf format "%I64u"
Quoted 6 lines · Jamie Lokier
Quoted 5 lines · Anthony Liguori
Quoted 3 lines · Consul
This patch suppresses a lot of mingw warnings like qemu-img.c:288: warning: format '%I64u' expects type 'unsigned int', but argument 2 has type '
uint64_t'
Quoted 7 lines
Quoted 2 lines
I'd rather see the warning fixed (by switching to PRIu64) than to have the warnings disabled.
Since that's in code for Windows, I'd rather see mingw's GCC fixed to recognise %I64u, since that's fine Windows code.
Cc'd to mingw-users list for that reason.
mingw-users is a closed list; it rejects the message. Never mind.
-- Jamie
Re: [Qemu-devel] Mingw GCC not recognising printf format "%I64u"
Quoted 8 lines
Quoted 7 lines · Jamie Lokier
Quoted 6 lines · Anthony Liguori
Quoted 4 lines · Consul
This patch suppresses a lot of mingw warnings like qemu-img.c:288: warning: format '%I64u' expects type 'unsigned int',
but argument 2 has type 'uint64_t'
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
I'd rather see the warning fixed (by switching to PRIu64) than to have
the warnings disabled.Since that's in code for Windows, I'd rather see mingw's GCC fixed to recognise %I64u, since that's fine Windows code.
I suppose Windows doesn't #define the now standard PRI*N macros:
http://www.opengroup.org/onlinepubs/009695399/basedefs/inttypes.h.html
else you'd use PRIu64.
I won't blame it for not doing so, BeOS didn't have them either (but hey, it was out before C99...).
François.
Re: [Qemu-devel] Mingw GCC not recognising printf format "%I64u"
Quoted 11 lines · François Revol
Quoted 11 lines
Quoted 9 lines · Jamie Lokier
Quoted 7 lines · Anthony Liguori
Quoted 3 lines · Consul
This patch suppresses a lot of mingw warnings like
qemu-img.c:288: warning: format '%I64u' expects type 'unsigned int', but argument 2 has type 'uint64_t'I'd rather see the warning fixed (by switching to PRIu64) than to have the warnings disabled.
Quoted 9 lines
Quoted 3 lines
Quoted 3 lines
Since that's in code for Windows, I'd rather see mingw's GCC fixed to recognise %I64u, since that's fine Windows code.
I suppose Windows doesn't #define the now standard PRI*N macros:
http://www.opengroup.org/onlinepubs/009695399/basedefs/inttypes.h.htmlelse you'd use PRIu64.
Or we can just do
#ifdef _WIN32
#define PRIu64 "%llu"
#endif
or whatever the correct format is.
Regards,
Anthony Liguori
Quoted 6 lines
I won't blame it for not doing so, BeOS didn't have them either (but hey, it was out before C99...).
François.
Re: [Qemu-devel] Mingw GCC not recognising printf format "%I64u"
Quoted 7 lines · Anthony Liguori
Or we can just do
#ifdef
_WIN32
#define PRIu64 "%llu"
#endifor whatever the correct format is.
Qemu does that already!
It's just it defines the macro to "%I64u" because that's the WIN32 way of writing it...
A quick Google reveals that "%llu" actually doesn't work on Mingw.
(Though, if you were compiling on Cygwin (the Linux-like environment for Windows), you must use "%llu". But that also defines _WIN32... ho hum).
-- Jamie
Quoted 15 lines
Regards,
Anthony Liguori
Quoted 7 lines
I won't blame it for not doing so, BeOS didn't have them either (but hey, it was out before C99...).
François.
Re: [Qemu-devel] Mingw GCC not recognising printf format "%I64u"
Quoted 4 lines · Jamie Lokier
Quoted 2 lines · Anthony Liguori
Or we can just do
Quoted 9 lines
Quoted 6 lines
#ifdef
_WIN32
#define PRIu64 "%llu"
#endifor whatever the correct format is.
Qemu does that already!
I don't think so. mingw32 actuallt defines PRIu64 as "%I64u" even though GCC doesn't like it. FWIW, the following seems to work for me:
/* Mingw has a broken PRIu64 */
#if defined(__MINGW32__)
#undef PRIu64
#define PRIu64 "Ld"
#endif
Regards,
Anthony Liguori
Quoted 32 lines
It's just it defines the macro to "%I64u" because that's the WIN32 way of writing it...
A quick Google reveals that "%llu" actually doesn't work on Mingw.
(Though, if you were compiling on Cygwin (the Linux-like environment for Windows), you must use "%llu". But that also defines
_WIN32... ho hum).-- Jamie
Quoted 14 lines
Regards,
Anthony Liguori
Quoted 7 lines
I won't blame it for not doing so, BeOS didn't have them either (but hey, it was out before C99...).
François.
[Qemu-devel] Re: Mingw GCC not recognising printf format "%I64u"
Quoted 9 lines · Anthony Liguori
I don't think so. mingw32 actuallt defines PRIu64 as "%I64u" even though GCC doesn't like it. FWIW, the following seems to work for me:
/* Mingw has a broken PRIu64 */
#ifdefined(__MINGW32__)
#undef PRIu64
#define PRIu64 "Ld"
#endif
Ld truncates the output. It appears to be a GCC-4.3 problem, GCC-3.4.2 is quite happy with I64u.
Re: [Qemu-devel] Mingw GCC not recognising printf format "%I64u"
In reply to Anthony LiguoriQuoted 8 lines · Anthony Liguori
Quoted 5 lines
Quoted 4 lines
#ifdef
_WIN32
#define PRIu64 "%llu"
#endifQemu does that already!
I don't think so. mingw32 actuallt defines PRIu64 as "%I64u" even though GCC doesn't like it.
Look again. qemu/qemu-common.h:
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define WINVER 0x0501 /* needed for ipv6 bits */
#include <windows.h>
...etc...
#define PRId64 "I64d"
#define PRIx64 "I64x"
#define PRIu64 "I64u"
#define PRIo64 "I64o"
#endif
The only condition is whether _WIN32 is defined, which means WIN32 API, except that it's also defined with Cygwin (and other unix emulations) which have quite different functions.
Quoted 7 lines
FWIW, the following seems to work for me:
/* Mingw has a broken PRIu64 */
#ifdefined(__MINGW32__)
#undef PRIu64
#define PRIu64 "Ld"
#endif
(Should by "Lu", btw).
How you checked it prints correctly? There are Googlable reports of people using "%lld" on Mingw saying that it doesn't print large 64-bit values correctly, because it truncates them to 32 bits, and trying "%I64u" and it works. Possibly due to Mingw programs calling Microsoft's C library, therefore being subject to Windowsness.
The same _could_ happen with "%Ld" or "%Lu", if Microsoft hasn't implemented that as 64-bit.
-- Jamie
Re: [Qemu-devel] Mingw GCC not recognising printf format "%I64u"
Quoted 25 lines · Jamie Lokier
Quoted 9 lines · Anthony Liguori
Quoted 7 lines
Quoted 5 lines
#ifdef
_WIN32
#define PRIu64 "%llu"
#endifQemu does that already!
I don't think so. mingw32 actuallt defines PRIu64 as "%I64u" even though GCC doesn't like it.
Look again.
qemu/qemu-common.h:#ifdef
_WIN32
#defineWIN32_LEAN_AND_MEAN
#define WINVER0x0501/* needed for ipv6 bits */
#include <windows.h>
...etc...
#define PRId64 "I64d"
#define PRIx64 "I64x"
#define PRIu64 "I64u"
#define PRIo64 "I64o"
#endif
Quoted 4 lines
The only condition is whether
_WIN32is defined, which means WIN32 API, except that it's also defined with Cygwin (and other unix emulations) which have quite different functions.
Okay, I wrote a small program that included inttypes.h. PRIu64 was defined as I64u.
Quoted 9 lines
Quoted 8 lines
FWIW, the following seems to work for me:
/* Mingw has a broken PRIu64 */
#ifdefined(__MINGW32__)
#undef PRIu64
#define PRIu64 "Ld"
#endif
Quoted 8 lines
(Should by "Lu", btw).
How you checked it prints correctly? There are Googlable reports of people using "%lld" on Mingw saying that it doesn't print large 64-bit values correctly, because it truncates them to 32 bits, and trying "%I64u" and it works. Possibly due to Mingw programs calling Microsoft's C library, therefore being subject to Windowsness.
I only tried with a small number so it could possibly truncate large numbers.
Regards,
Anthony Liguori
Quoted 7 lines
The same _could_ happen with "%Ld" or "%Lu", if Microsoft hasn't implemented that as 64-bit.
-- Jamie
[Qemu-devel] Re: Mingw GCC not recognising printf format "%I64u"
Quoted 1 line · Anthony Liguori
Okay, I wrote a small program that included
inttypes.h. PRIu64 was defined as I64u.
This bug should be fixed in GCC-4.4.0 (and backported to 3.4.2 MinGW's stable) However the latest version ported to MinGW is still 4.3.0. Mind you I64u in the format line still gives the correct result, only this annoying warning is the problem. Other suggested format options silenced the warning, but also truncated the result :(
#include<stdio.h>
#include<inttypes.h>
//#define PRIu64 "I64u"
int main() {
unsigned __int64 x = 1122334455667788LL;
printf("Number: %"PRIu64"\n", x);
return 0;
}Re: [Qemu-devel] Re: Mingw GCC not recognising printf format "%I64u"
Quoted 4 lines · Consul
Quoted 1 line · Anthony Liguori
Okay, I wrote a small program that included
inttypes.h. PRIu64 was defined as I64u.This bug should be fixed in GCC-4.4.0 (and backported to 3.4.2 MinGW's stable) However the latest version ported to MinGW is still 4.3.0. Mind you I64u in the format line still gives the correct result, only this annoying warning is the problem. Other suggested format options silenced the warning, but also truncated the result :(
Okay, then we can just ignore it for now.
Regards,
Anthony Liguori
Quoted 11 lines
#include<stdio.h>
#include<inttypes.h>
//#define PRIu64 "I64u"int main() { unsigned __int64 x = 1122334455667788LL; printf("Number: %"PRIu64"\n", x); return 0; }