bug-gnulib
[Top][All Lists]
Advanced

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

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


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

Hello,

I'm not sure if this is a gnulib question per-se, but I'm hopeful you could 
perhaps advise me.

I use the following (or similar) code in my project:

    size_t line=42;
    error(EXIT_FAILURE, 0, _("error in line %zu"), line);

The "%zu" works for 'size_t' on all unix-like systems I've tried (32 and 64 
bit), and on Cygwin 64bit.
However, it fails when cross-compiling for windows with mingw (both i868 and 
x86_64 versions), with the following:

    warning: unknown conversion type character 'z' in format [-Wformat]
    warning: too many arguments for format [-Wformat-extra-args]

With mingw (due to msvcrt implementation, I assume) the correct type is "%Iu", 
as listed here:
http://msdn.microsoft.com/en-us/library/tcxf1dw6%28v=vs.71%29.aspx


Note that if this had been a "printf" function call, then compiling with

    CFLAGS=-D__USE_MINGW_ANSI_STDIO=1

Would have 'fixed' it (or at least worked around it) by substituting 'printf' 
with the internal '__mingw_printf' .
But because this is 'error()' from gnulib, it is not replaces and therefore 
triggers this error.

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.


Thanks,
 - Assaf



reply via email to

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