c - scanf GCC for long double -
this question has answer here:
- scanf not taking in long double 5 answers
i'm using gcc 4.8.1 std=c99 on windows 7. what's correct place holder long double when using scanf
, fscanf
? tried %lf , %lf , neither working. compile command gcc -std=c99 main.c -o main.exe
. when omit std=c99
works fine.
#include <stdlib.h> #include <stdio.h> int main() { long double x = 0; scanf("%lf", &x); printf("x = %lf\n", x); return 0; }
it works fine me, on centos 6.6, or without -std=c99:
$ gcc --version gcc (gcc) 4.4.7 20120313 (red hat 4.4.7-11) copyright (c) 2010 free software foundation, inc. $ gcc x.c -o x -std=c99 -wall -pedantic $ ./x 123.456 x = 123.456000 $ gcc x.c -o x -wall -pedantic $ ./x 123.456 x = 123.456000
i'm assuming you're on linux (or mac osx), , assume you're using libc matches installed gcc.
however
there issues if you're using gcc mingw on windows:
scanf not taking in long double
dev-c++ uses mingw, uses gcc compiler , microsoft runtime library. unfortunately, components disagree on underlying type used long double (64 vs. 80 or 96 bits, think). windows assumes long double same size double; gcc makes long double bigger.
either choice valid, combination results in broken c , c++ implementation.
Comments
Post a Comment