From: Markus S. <MS...@de...> - 2005-09-16 22:39:52
|
Hello, I want to print out a 64 bit variable in hex in a C program compiled with MinGW. As MinGW uses printf from the MS C library, the format is not the normal %llx,but has to be %I64x ... unsigned long long ttt; ttt = 0x123456789abcdef; printf("longlongI64x=%I64x length=%d\n", ttt, sizeof(ttt)); ... compiling this with "gcc -Wall tt.c" shows the following warning: tt.c:24: warning: `I' flag used with `%x' printf format tt.c:24: warning: unsigned int format, different type arg (arg 2) (the actual output of the printf is as it should be) Actually I want a fixed width output with leading zeros: ... printf("longlongI64x=%016I64x\n", ttt); ... which even warns about too many arguments: tt.c:24: warning: unknown conversion type character `I' in format tt.c:24: warning: too many arguments for format Is there are way to avoid the warnings (besides omiting the option -Wall ?). That is somehow teach gcc the meaning of the Microsoft format %I64 ? And yet another question: The program shall compile for different platforms. It would be quite some work and an ugly code, if any printf, sprintf, fprintf, sanf, sscanf, ... had to be surrounded by #ifdef __MINGW32_ ... #elif. Does anyone have an idea how to choose between %llx , %lld and %I64x, %I64d in just one central position? One possibility would of course be, to write an own printf, that contains the #ifdef __MINGW32_ ... #elif and calls the libraries printf. But that would even have to parse, if it was called with %llx or %lld. But maybe there is a simpler way? Markus. PS: In case the version is important: $ gcc -v Reading specs from d:/bin/MinGW/bin/../lib/gcc-lib/mingw32/3.2.3/specs Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable-languages=c++,f77,objc --disable-win32-registry --disable-shared --enable-sjlj-exceptions Thread model: win32 gcc version 3.2.3 (mingw special 20030504-1) $ uname -a MINGW32_NT-5.0 B5561X1D 1.0.10(0.46/3/2) 2004-03-15 07:17 i686 unknown MinGW 4.1.0 Operating System: Windows 2000 |
From: Danny S. <dan...@cl...> - 2005-09-16 22:51:24
|
----- Original Message ----- From: "Markus Selve Sent: Saturday, 17 September 2005 10:39 > > Is there are way to avoid the warnings (besides omiting the option -Wall > ?). That is somehow teach gcc the meaning of the Microsoft format %I64 ? Yes. > > And yet another question: > > The program shall compile for different platforms. It would be quite some > work and an ugly code, if any printf, sprintf, fprintf, sanf, sscanf, ... > had to be surrounded by #ifdef __MINGW32_ ... #elif. > > Does anyone have an idea how to choose between %llx , %lld and %I64x, %I64d > in just one central position? One possibility would of course be, to write > an own printf, that contains the #ifdef __MINGW32_ ... #elif and calls > the libraries printf. But that would even have to parse, if it was called > with %llx or %lld. But maybe there is a simpler way? > #include <inttypes.h> |
From: Brian D. <br...@de...> - 2005-09-16 23:03:05
|
Markus Selve wrote: > Is there are way to avoid the warnings (besides omiting the option -Wall > ?). That is somehow teach gcc the meaning of the Microsoft format %I64 ? You could try "-Wall -Wno-format" to get everything but the printf checking. But that's just a work-around, in order to fix it the right way gcc would have to be patched to know about the MSVC extensions. > in just one central position? One possibility would of course be, to write > an own printf, that contains the #ifdef __MINGW32_ ... #elif and calls > the libraries printf. But that would even have to parse, if it was called > with %llx or %lld. But maybe there is a simpler way? It sounds like a wrapper might be the only way. As users we don't have any control over MSVCRT so I don't think there's any way to make it recognise %lld. Brian |
From: Danny S. <dan...@cl...> - 2005-09-18 02:10:45
|
----- Original Message ----- From: "Markus Selve> > Is there are way to avoid the warnings (besides omiting the option -Wall > ?). That is somehow teach gcc the meaning of the Microsoft format %I64 ? http://gcc.gnu.org/ml/gcc-patches/2004-11/msg02296.html is a start. The patch has some problems. I can't remember what happened to the revised version of the patch that did work, I'll look for it and ping gcc list once gcc trunk branches A slightly different patch is in the mingw distro of gcc-3.4.4 Danny |
From: Luke D. <cod...@ho...> - 2005-09-19 15:04:22
|
----- Original Message ----- From: "Markus Selve" <MS...@de...> To: <min...@li...> Sent: Saturday, September 17, 2005 6:39 AM Subject: [Mingw-users] Using %I64 in printf and avoiding compiler warnings > Does anyone have an idea how to choose between %llx , %lld and %I64x, > %I64d > in just one central position? One possibility would of course be, to write > an own printf, that contains the #ifdef __MINGW32_ ... #elif and calls > the libraries printf. But that would even have to parse, if it was called > with %llx or %lld. But maybe there is a simpler way? > > Markus. #ifdef __MINGW32__ #define INT64_FORMAT "I64" #else #define INT64_FORMAT "ll" #endif printf("longlongI64x=%" INT64_FORMAT "x length=%d\n", ttt, sizeof(ttt)); Not highly readable but easier than the alternatives. Luke |