【发布时间】:2021-08-30 00:30:39
【问题描述】:
我正在使用 Windows 10 和 MinGW GCC 编译器(不是 mingw64 编译器),但是当我尝试这段代码时, 这是我的 GCC 版本,
C:\Users\94768>gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/6.3.0/lto-wrapper.exe
Target: mingw32
Configured with: ../src/gcc-6.3.0/configure --build=x86_64-pc-linux-gnu --host=mingw32 --target=mingw32 --with-gmp=/mingw --with-mpfr --with-mpc=/mingw --with-isl=/mingw --prefix=/mingw --disable-win32-registry --with-arch=i586 --with-tune=generic --enable-languages=c,c++,objc,obj-c++,fortran,ada --with-pkgversion='MinGW.org GCC-6.3.0-1' --enable-static --enable-shared --enable-threads --with-dwarf2 --disable-sjlj-exceptions --enable-version-specific-runtime-libs --with-libiconv-prefix=/mingw --with-libintl-prefix=/mingw --enable-libstdcxx-debug --enable-libgomp --disable-libvtv --enable-nls
Thread model: win32
gcc version 6.3.0 (MinGW.org GCC-6.3.0-1)
代码是,
#include <stdio.h>
void main() {
float a = 1.12345;
double b = 1.12345;
long double c = 1.12345;
printf("float value is is %f\n", a);
printf("double value is %lf\n", b);
printf("long double value is %Lf\n", c);
}
我得到的输出不是我所期望的,我不明白这里有什么问题,我是 C 编程的绝对初学者。
float value is 1.123450
double value is 1.123450
long double value is -0.000000
非常感谢您的指导!
【问题讨论】:
-
看起来这是一个编译器错误。我不认为这是故意的。
-
当没有其他 FP 数学运算时,一些编译器会遇到
printf()的问题。 -
我也试过 mingw64 编译器,它也可以。
-
我同意@bumbread,这看起来像一个编译器/工具链错误。在Compiler Explorer 上使用各种编译器(包括 x86-64 gcc 6.3)对其进行测试会得到预期的结果。