← Back to team overview

kicad-developers team mailing list archive

Re: Printing size_t on MSW (%zu)

 

I'm guessing because mingw is providing a special implementation for printf
(and related functions) that supports %zu instead of linking to the old C89
one, but the GCC attribute checker is not aware of that.

On Fri, Jan 3, 2020 at 12:43 PM jp charras <jp.charras@xxxxxxxxxx> wrote:

> After some tests:
>
> printf("test %zu", size_t(1) );
>
> works, and there is no compil warning.
>
> Functions that generate a warning about %zu format are:
> StrPrintf()
> OUTPUTFORMATTER::Print()
> (see richio.h)
>
> they have the attribute:
> __attribute__ ((format (printf, 2, 3)))
> or
> __attribute__ ((format (printf, 3, 4)))
>
> And therefore GCC verify the format and the variable argument list, like
> for a printf.
>
> For some reason, %zu is seen as valid for printf, but not for functions
> having the printf attribute.
>
>
> Le 03/01/2020 à 16:16, Mark Roszko a écrit :
> > wxWidgets has a interesting maze of macros to determine how to do
> > printf on Windows. I wonder what it ends up doing. There is a special
> > case just for MINGW32 but not MINGW64.
> >
> >
> https://github.com/wxWidgets/wxWidgets/blob/cc931612eec2e3ea49200ebff45042135f3c3f9c/include/wx/wxcrtvararg.h#L84
> >
> >
> > On Fri, Jan 3, 2020 at 10:05 AM jp charras <jp.charras@xxxxxxxxxx>
> wrote:
> >>
> >> Le 03/01/2020 à 15:58, Jon Evans a écrit :
> >>> So maybe it's a 32-bits vs 64-bits thing.
> >>> If you add a line like
> >>> #define __USE_MINGW_ANSI_STDIO 1
> >>> at the top of that source file, does it work?
> >>
> >> No.
> >> I still have the compil message:
> >> warning: unknown conversion type character 'z' in format [-Wformat=]
> >>
> >>>
> >>> On Fri, Jan 3, 2020 at 9:32 AM jp charras <jp.charras@xxxxxxxxxx
> >>> <mailto:jp.charras@xxxxxxxxxx>> wrote:
> >>>
> >>>     Le 03/01/2020 à 15:10, Jon Evans a écrit :
> >>>     > I found it defined in
> >>>     >
> >>>
>  C:\msys64\mingw64\include\c++\8.3.0\x86_64-w64-mingw32\bits\os_defines.h
> >>>     > on my machine.
> >>>     > @JP -- what platform did you use (Windows version / MSYS version
> /
> >>>     etc)
> >>>     > where you saw the issue?
> >>>
> >>>     I confirm the %zu is not working on my install.
> >>>
> >>>     m_out->Print( aNestLevel+1, "(drawings %zu)\n",
> >>>     aBoard->Drawings().size() );
> >>>
> >>>     generates the warning:
> >>>     warning: unknown conversion type character 'z' in format
> [-Wformat=]
> >>>
> >>>     on my install:
> >>>
> >>>     Platform: Windows 7 (build 7601, Service Pack 1), 32 bit, Little
> endian,
> >>>     wxMSW
> >>>     Build Info:
> >>>         wxWidgets: 3.1.3 (wchar_t,wx containers)
> >>>         Boost: 1.71.0
> >>>         OpenCASCADE Community Edition: 6.8.0
> >>>         Curl: 7.66.0
> >>>         Compiler: GCC 9.2.0 with C++ ABI 1013
> >>>
> >>>     And I never saw %zu working on my W7 32 bits install.
> >>>
> >>>
> >>>     >
> >>>     > On Fri, Jan 3, 2020 at 9:02 AM Seth Hillbrand <
> seth@xxxxxxxxxxxxx
> >>>     <mailto:seth@xxxxxxxxxxxxx>
> >>>     > <mailto:seth@xxxxxxxxxxxxx <mailto:seth@xxxxxxxxxxxxx>>> wrote:
> >>>     >
> >>>     >     On 2020-01-02 17:19, Jon Evans wrote:
> >>>     >
> >>>     >     > Hi all,
> >>>     >     >
> >>>     >     > Context:
> >>>     >     >
> >>>
> https://gitlab.com/kicad/code/kicad/merge_requests/28#note_264910682
> >>>     >     >
> >>>     >     > I have heard there are issues using "%zu" format specifier
> on
> >>>     >     > Windows/mingw, because mingw links against a very old
> >>>     Windows library
> >>>     >     > that does not support the C99 standard.
> >>>     >     >
> >>>     >     > I have also heard that this isn't an issue anymore because
> of
> >>>     >     > __USE_MINGW_ANSI_STDIO in wxWidgets.
> >>>     >     >
> >>>     >     > I tried to reproduce this problem on my Windows 10 machine
> but
> >>>     >     couldn't
> >>>     >     > -- using %zu works fine.
> >>>     >     >
> >>>     >     > Does anyone know if this is still a problem on any of our
> >>>     supported
> >>>     >     > platforms?
> >>>     >     >
> >>>     >     > Thanks,
> >>>     >     > -Jon--
> Jean-Pierre CHARRAS
>
> _______________________________________________
> Mailing list: https://launchpad.net/~kicad-developers
> Post to     : kicad-developers@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~kicad-developers
> More help   : https://help.launchpad.net/ListHelp
>

References