printf with -D__USE_MINGW_ANSI_STDIO &am...


  • Anonymous


    I am able to display long double values with printf if I use the compilation  flag -D__USE_MINGW_ANSI_STDIO.

    However, if I also include <fstream> in my program, then printf does not display long double values correctly anymore. I even tried using ::printf, but still the same result. It's enough that <fstream> be included for this issue to happen.

    For instance, the program below outputs 3.645200e-4951, but if I include fstream (uncomment that line) then the result is 1.133047e-317

    How can I avoid this? I want to use the version of printf that outputs the correct result

    Somebody at the mingw's mailing list has already verified that this is NOT an issue with them but with your project:

    Thanks in advance

    P.S. including the flags -ansi or -posix does not make any difference. As long as I include fstream I can't output long double values correctly

    I'm using Windows 7 pro 64 bit version and the following:

    $ x86_64-w64-mingw32-g++.exe -dumpversion
    $ uname -srv
    CYGWIN_NT-6.1-WOW64 1.7.9(0.237/5/3) 2011-03-29 10:10
    /* Compile under cygwin with this command line 
    x86_64-w64-mingw32-g++.exe -D__USE_MINGW_ANSI_STDIO  test_fstream.cpp -o test_fstream && ./test_fstream.exe 
    // Name this program test_fstream.cpp 
    #include <math.h> 
    #include <stdio.h> 
    //#include <fstream> 
    int main(int argc, char* argv[]) 
            long double Exp3 = -11399.0L, result, e=2.71828182845905L; 
            result = powl(e, Exp3); 
            printf("%Le\n", result); 
            return 0; 
  • Ozkan Sezer
    Ozkan Sezer

    fstream includes cstdio who undefines printf & co and that probably messes our _mingw_print_push.h and _mingw_print_pop.h magic.  Don't know what the best solution would be with that.  Kai?