From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17447 invoked by alias); 19 Aug 2014 20:50:53 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 17362 invoked by uid 48); 19 Aug 2014 20:50:42 -0000 From: "jb at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/61847] bug in gfortran runtime: digits cut off when reading floating point number Date: Tue, 19 Aug 2014 20:50:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 4.8.3 X-Bugzilla-Keywords: X-Bugzilla-Severity: enhancement X-Bugzilla-Who: jb at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: jvdelisle at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-08/txt/msg01307.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61847 Janne Blomqvist changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jb at gcc dot gnu.org --- Comment #19 from Janne Blomqvist --- (In reply to Jerry DeLisle from comment #17) > I have a patch in the works. The idea is to query the locale at the time > the Unit is connected and save the LC_NUMERIC character in the unit > structure. Then, if the decimal character matches the DECIMAL_STATUS > (decimal="point" or decimal="comma") active at the time of reading, change > the decimal character internally to the current locale character previously > saved. This way, only one call to locale is needed per unit connection, > preserving efficiency. The real string will then be converted correctly, > regardless of locale. While clever, I'm not sure this approach works. A program can change the locale between opening the file and reading from it (potentially in another thread, since the locale is a process-wide property). What can be done instead is to use the POSIX 2008 extended locale functionality (newlocale) to create a "locale object" in the default C locale and then use functions like strtod_l (for some reason not in POSIX 2008, though at least glibc and BSD/OSX have it, IIRC) that take such a locale object as argument. This is fairly new though and not available everywhere, but ought to be robust. See also PR 47007. As an aside, AFAIK the "C" and "POSIX" locales are the same, just two names for the same thing. "C" might be more portable, as that should work everywhere there is a C implementation.