Re: problem with gnome_init
- From: George <jirka 5z com>
- To: gnome-devel-list gnome org
- Subject: Re: problem with gnome_init
- Date: Sat, 23 Sep 2000 13:52:55 -0700
On Sun, Sep 24, 2000 at 12:19:11AM +0200, Eric Laeuffer wrote:
> Hello,
>
> I beggining to write a gnome software, but I have a strange problem.
>
> I am doing exactly the same process before and after the gnome_init
> function and I don't obtain the same result.
>
> It seems that the problem is coming from sscanf. The sscanf just parses
> a line and doesn't return the same things.
>
> I attached to this email a small source which show this problem.
>
> Have you got an idea about this issue ?
Well the problem is locale. Since I suppose you are set up in french locale,
gnome_init will call setlocale. This will change the behaviour of
scanf/printf functions. Especially with respect to floating point numbers.
In french locale you are going to read/write floats in "1234,5678" format
while in C locale it's "1234.5678". So if you try to read the bottom one
in french locale, you are likely gonna get screwed.
This can be quite a problem, especially since most people aren't aware of it
and happily read/write floats to files and expect then to read the same thing
using scanf/printf.
The "workaround" in various places in gnome is to do the following:
char *old_locale;
old_locale = g_strdup (setlocale (LC_NUMERIC, NULL));
setlocale (LC_NUMERIC, "C");
/* Do printf/scanf here */
setlocale (LC_NUMERIC, old_locale);
g_free (old_locale);
This will just set the numeric locale to C and force things to be done the
"C" locale way, and thus portably accross locales.
Note that other functions also have trouble. Basically anything dealing with
string<->float conversions, such as strtod.
George
--
George <jirka 5z com>
Personally, I'm always ready to learn, although I do not
always like being taught.
-- Winston Churchill
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]