Re: [gtk-list] Re: locale affects (infects? ;) strtod()
- From: Owen Taylor <owt1 cornell edu>
- To: Gtk+ Mailing List <gtk-list redhat com>, GNOME mailing-list <gnome nuclecu unam mx>
- Subject: Re: [gtk-list] Re: locale affects (infects? ;) strtod()
- Date: 20 Dec 1997 12:32:10 -0500
Tom Tromey <tromey@creche.cygnus.com> writes:
> Tim> if strtod() can't be used to parse _international_ *rc files,
> Tim> which function should be used instead to do string->float
> Tim> conversions?
>
> As you've discovered, strtod() does locale-specific conversion. If
> you want to use the C locale rules, then set the locale to C before
> calling strtod(). You only have to set LC_NUMERIC:
>
> #include <locale.h>
>
> char *old = setlocale (LC_NUMERIC, "C");
> ... strtod (...) /* will use C rules */
> setlocale (LC_NUMERIC, old);
The only problem with this is that it isn't thread safe. (I think
locales are global, not thread-specific). But I don't know if
anything can be doen about that...
Regards,
Owen
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]