This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/61847] bug in gfortran runtime: digits cut off when reading floating point number


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61847

Janne Blomqvist <jb at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jb at gcc dot gnu.org

--- Comment #19 from Janne Blomqvist <jb at gcc dot gnu.org> ---
(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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]