Re: [gtk-list] Re: locale affects (infects? ;) strtod()




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]