locale for floating point numbers #3
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
(Continuation of https://github.com/jacobsa/jsoncpp/pull/2, rebased against current master)
It think the problem will be there both under Linux and Windows (I was using Linux).
The problem is that setlocale() will replace the locale globally (which means it is a bad idea to call it from a library) and uselocale() is POSIX-specific.
I wasn't setting the locale during compilation but when executing the binary.
Resetting the LC_NUMERIC locale to "C" will work, but that means that either the library has to do it (which IMHO is a bad idea when doing it globally) or the program has to do it. I think that requiring the program to change the locale is not a good idea either; many developers will never notice the problem when they are using a US locale for development.
Another possibility to fix the problem would be to replace the ',' by a '.' after calling snprintf(), AFAIK there are no locales which use something other than '.' or ','. Doing this feels weird, but probably will work and has almost the same performance as just calling snprintf().