Menu

#295 _pformat does not support %zd of C99

closed-invalid
nobody
crt (86)
5
2012-05-10
2012-05-08
Ray Linn
No

in C99 ,%zd is used to print the size_t, for example

#include <stdio.h>
#include <string.h>
int main(void)
{
int a =1;
char b[4] ="aaa";
printf("%zd %zd %lu\n",sizeof a,sizeof(int),sizeof a);
printf("%zd %zd\n",sizeof b,strlen(b));
return 0;
}

gcc -std=c99 foo.c -o foo.exe

looks current 2.0.2 runtime does not support this format, and only characters 'zd' is print out. has this been fixed on 2.0.3

Discussion

  • Ray Linn

    Ray Linn - 2012-05-08

    This issue is related with sprintf "%zd" format which is a C99 feature.
    To enable sprintf "%zd" format, Ruby 1.9.3 defines macro _GNU_SOURCE.
    If _GNU_SOURCE is defined, MinGW32 defines __USE_MINGW_ANSI_STDIO macro.
    But MinGW64 ignores _GNU_SOURCE macro.

    The workaround is define macro __USE_MINGW_ANSI_STDIO like this:
    ./configure --build=x86_64-w64-mingw32 CFLAGS="-O2 -finline-functions -D__USE_MINGW_ANSI_STDIO"

    I am not sure this is a bug, but I found MinGW64 cannot handle -std=c99 flag in this case.

    Consider this:

    C:\work>type foo.c
    #include <stdio.h>
    int main()
    {
    printf("%zd",(size_t)10);
    return 0;
    }

    C:\work>gcc -v
    Using built-in specs.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=c:/mingw47/mingw/bin/../libexec/gcc/i686-pc-mingw32/4.7.0/lt
    o-wrapper.exe
    Target: i686-pc-mingw32
    Configured with: ../src/configure --prefix=/c/temp/gcc/dest --with-gmp=/c/temp/g
    cc/gmp --with-mpfr=/c/temp/gcc/mpfr --with-mpc=/c/temp/gcc/mpc --enable-language
    s=c,c++ --with-arch=i686 --with-tune=generic --disable-libstdcxx-pch --disable-n
    ls --disable-shared --disable-sjlj-exceptions --disable-win32-registry --enable-
    checking=release --enable-lto
    Thread model: win32
    gcc version 4.7.0 (GCC)

    C:\work>gcc -std=c99 foo.c -ofoo.exe

    C:\work>foo
    10

    C:\work>gcc -D_GNU_SOURCE foo.c -ofoo.exe

    C:\work>foo
    10

    C:\work>gcc -D__USE_MINGW_ANSI_STDIO foo.c -ofoo.exe

    C:\work>foo
    10

    C:\work>gcc -v
    Using built-in specs.
    COLLECT_GCC=gcc
    COLLECT_LTO_WRAPPER=c:/mingw64_7/bin/../libexec/gcc/x86_64-w64-mingw32/4.7.0/lto
    -wrapper.exe
    Target: x86_64-w64-mingw32
    Configured with: ../gcc-4.7.0/configure --build=x86_64-w64-mingw32 --enable-targ
    ets=all --disable-multilib --enable-64bit --prefix=/mingw64 --with-sysroot=/ming
    w64 --disable-shared --enable-static --disable-nls --enable-version-specific-run
    time-libs --disable-win32-registry --without-dwarf2 --enable-sjlj-exceptions --e
    nable-fully-dynamic-string --enable-languages=c,ada,lto,c++,objc,obj-c++,fortran
    --enable-libgomp --enable-lto --enable-libssp -enable-gnattools --disable-boots
    trap --with-gcc --with-gnu-as --with-gnu-ld --with-stabs --enable-interwork --wi
    th-mpfr-include=/home/beta/gcc-build/../gcc-4.7.0/mpfr/src --with-mpfr-lib=/home
    /beta/gcc-build/mpfr/src/.libs
    Thread model: win32
    gcc version 4.7.0 (GCC)

    C:\work>gcc -std=c99 foo.c -ofoo.exe

    C:\work>foo
    zd

    C:\work>gcc -D_GNU_SOURCE foo.c -ofoo.exe

    C:\work>foo
    zd

    C:\work>gcc -D__USE_MINGW_ANSI_STDIO foo.c -ofoo.exe

    C:\work>foo
    10

     
  • Kai Tietz

    Kai Tietz - 2012-05-10

    This bug report is invalid. The option '-std=c99' just affects the compiler, not the runtime-function used. This is controlled by the switch - I begin to hate this define's name as it is too long ;) - __USE_MINGW_ANSI_STDIO. Please compile your test with additional option '-D__USE_MINGW_ANSI_STDIO=1' and you will see it works as desired.

    Close this bug as invalid.

     
  • Kai Tietz

    Kai Tietz - 2012-05-10
    • status: open --> closed-invalid
     

Log in to post a comment.

MongoDB Logo MongoDB