hyperrealm / libconfig

C/C++ library for processing configuration files
https://hyperrealm.github.io/libconfig/
GNU Lesser General Public License v2.1
1.11k stars 362 forks source link

config_lookup_float() produces value of 0, but on Linux only #135

Closed jacob-pro closed 4 years ago

jacob-pro commented 5 years ago

The same code is being compiled for Windows & Linux, and using the same copy of libconfig-1.7.2 source. The text file contains values like this (the file is being created by config_write_file in the first place):

latitude = 51.374286;
longitude = -3.82313;

And is then read using

    config_t cfg;
    config_init(&cfg);
    if (!config_read_file(&cfg, fileName)) {
        // handle error
    }
    double lat, lon;
    config_lookup_float(&cfg, "latitude", &lat);
    config_lookup_float(&cfg, "longitude", &lon);

On Windows this works exactly as expected, but on Linux the value in lat and lon is always zero.

The issue appears to be somewhere in the process of parsing the text file because my debugger can see the config_setting_set_float is being called with a value of 0 during the read file operation.

hyperrealm commented 5 years ago

I can't reproduce this. It works fine on my Linux system.

Floating point values are parsed using atof() ... all I can think of is that your system is set to a locale other than "C". Were there any warnings from the configure script about locale functions being unavailable? Try manually setting the locale to "C" before parsing the file and see if that fixes it.

setlocale(LC_NUMERIC, "C");