bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Portable printing of 'size_t' (especially with mingw for windows)


From: Assaf Gordon
Subject: Re: Portable printing of 'size_t' (especially with mingw for windows)
Date: Thu, 11 Sep 2014 14:20:52 -0400
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0


On 09/11/2014 11:48 AM, Pádraig Brady wrote:

I wonder if there's a definition in "inttypes.h" or similar that would be a 
correct one to use,
or if there's another portable way to compile it.

I've some notes on printing int values at:
http://www.pixelbeat.org/programming/gcc/int_types/

That's a very informative example, thanks!
For reference, below are the warnings that this example program gives with 
mingw.

I wasn't aware of the %zu issue TBH and I notice coreutils also uses %zu
You can still apply the casting technique at the above link, like:

   error(EXIT_FAILURE, 0, _("error in line %"PRIuMAX), (uintmax_t) line);

Thanks,
 - Assaf


## 64bit mingw with special CFLAG, no warnings:
$ x86_64-w64-mingw32-gcc -Wall -Wextra -D__USE_MINGW_ANSI_STDIO=1 int_types.c

## 64bit mingw
$ x86_64-w64-mingw32-gcc -Wall -Wextra int_types.c
int_types.c: In function 'main':
int_types.c:38:12: warning: unknown conversion type character 'z' in format 
[-Wformat]
int_types.c:38:12: warning: format '%x' expects argument of type 'unsigned 
int', but argument 2 has type 'long long unsigned int' [-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'z' in format 
[-Wformat]
int_types.c:38:12: warning: format '%lx' expects argument of type 'long 
unsigned int', but argument 3 has type 'unsigned int' [-Wformat]
int_types.c:38:12: warning: format '%u' expects argument of type 'unsigned 
int', but argument 4 has type 'long long unsigned int' [-Wformat]
int_types.c:38:12: warning: format '%x' expects argument of type 'unsigned 
int', but argument 5 has type 'long unsigned int' [-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'j' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'j' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'j' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'j' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'j' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'j' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'z' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'z' in format 
[-Wformat]
int_types.c:38:12: warning: too many arguments for format [-Wformat-extra-args]
        

## 32bit mingw with special CFLAGS, no warnings:
$ i686-w64-mingw32-gcc -Wall -Wextra -D__USE_MINGW_ANSI_STDIO=1 int_types.c

## 32bit mingw
$ i686-w64-mingw32-gcc -Wall -Wextra int_types.c
int_types.c: In function 'main':
int_types.c:38:12: warning: unknown conversion type character 'z' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'z' in format 
[-Wformat]
int_types.c:38:12: warning: format '%lx' expects argument of type 'long 
unsigned int', but argument 3 has type 'unsigned int' [-Wformat]
int_types.c:38:12: warning: format '%x' expects argument of type 'unsigned 
int', but argument 5 has type 'long unsigned int' [-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'j' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'j' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'j' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'j' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'j' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'j' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'z' in format 
[-Wformat]
int_types.c:38:12: warning: unknown conversion type character 'z' in format 
[-Wformat]
int_types.c:38:12: warning: too many arguments for format [-Wformat-extra-args]


##
## mingw compilers based on gcc-4.6, obtained from http://www.emdebian.org/
##
$ i686-w64-mingw32-gcc -v
Using built-in specs.
COLLECT_GCC=i686-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-w64-mingw32/4.6/lto-wrapper
Target: i686-w64-mingw32
Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr 
--includedir='/usr/include' --mandir='/usr/share/man' 
--infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var 
--libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode 
--disable-dependency-tracking --prefix=/usr --enable-shared --enable-static 
--disable-multilib --enable-linker-build-id --with-system-zlib 
--libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib 
--enable-libstdcxx-time=yes --with-tune=generic 
--enable-version-specific-runtime-libs --enable-threads=win32 
--enable-fully-dynamic-string --enable-sjlj-exceptions 
--enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-lto --with-plugin-ld 
--target=i686-w64-mingw32 --with-gxx-include-dir=/usr/include/c++/4.6 
--with-as=/usr/bin/i686-w64-mingw32-as --with-ld=/usr/bin/i686-w64-mingw32-ld
Thread model: win32
gcc version 4.6.3 (GCC)

$ x86_64-w64-mingw32-gcc -v
Using built-in specs.
COLLECT_GCC=x86_64-w64-mingw32-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-w64-mingw32/4.6/lto-wrapper
Target: x86_64-w64-mingw32
Configured with: ../../src/configure --build=x86_64-linux-gnu --prefix=/usr 
--includedir='/usr/include' --mandir='/usr/share/man' 
--infodir='/usr/share/info' --sysconfdir=/etc --localstatedir=/var 
--libexecdir='/usr/lib/gcc-mingw-w64' --disable-maintainer-mode 
--disable-dependency-tracking --prefix=/usr --enable-shared --enable-static 
--disable-multilib --enable-linker-build-id --with-system-zlib 
--libexecdir=/usr/lib --without-included-gettext --libdir=/usr/lib 
--enable-libstdcxx-time=yes --with-tune=generic 
--enable-version-specific-runtime-libs --enable-threads=win32 
--enable-fully-dynamic-string --enable-sjlj-exceptions 
--enable-languages=c,c++,fortran,objc,obj-c++,ada --enable-lto --with-plugin-ld 
--target=x86_64-w64-mingw32 --with-gxx-include-dir=/usr/include/c++/4.6 
--with-as=/usr/bin/x86_64-w64-mingw32-as 
--with-ld=/usr/bin/x86_64-w64-mingw32-ld
Thread model: win32
gcc version 4.6.3 (GCC)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]