Long double text misprinted with iostreams on MinGW

Consider the code

#include <iostream>

int main() {
  std::cout << 4.2L;
}

Compile it on MinGW and run the results in the next release:

> g++ test.cc
> a.exe
-7.89773e-278

Is this a bug in MinGW and is there a fix or workaround?

Update:

A similar problem is printfdescribed in this question :

#include <cstdio>

int main() {
  std::printf("%Lg", 4.2L); // prints -7.89773e-278
}

However, the problem with printfcan be fixed by determining __USE_MINGW_ANSI_STDIOuntil it can be, so I think it deserves a separate question.

+3
source share
1 answer

not MinGW... , , , , Microsoft C/++, MinGW. , , , .

, , , Microsoft - long double MSVC , , -, MSVCRT.DLL; (, , , , ", MSVC long double", , , , long, long double bare double).

, GCC , , MinGW long double, double; - 80- , - 64- 64- MSVC . , 80- , , , , ; ( - 80- long double, 64-, , , ).

, MSVCRT.DLL 64- double, MinGW / C printf, 80- ; - ++. , ++ - MinGW, - ++; MSVCRT.DLL . , , : -

  • long double double; ( , Microsoft, long double).
  • long double, double .
  • / C - ++ MinGW printf -posix, -D_GNU_SOURCE, -D_BSD_SOURCE, -D_XOPEN_SOURCE=700 -D_POSIX_C_SOURCE=200809L ( , #define , #include). , _XOPEN_SOURCE _POSIX_C_SOURCE; (, , , , -D__USE_MINGW_ANSI_STDIO; , , " " , , , , , ).
  • C snprintf long double C, ++ , , ++ long double. (IIRC, Microsoft snprintf - _snprintf - , ANSI, 80- long double).
+1

Source: https://habr.com/ru/post/1689987/


All Articles