I think that it's safe to say that C locales are universally recognized as a bad idea.
Writing an application that tries to parse or write text-based machine formats (which happens quite often) with C standard library functions gets near-impossible if you have to account for locale being set to anything different than "C"
. Since locale is normally per-process (and setlocale
is often not thread-safe), if you are writing a library or you have a multithreaded program it's not safe even to do setlocale(LC_ALL, "C")
and restore it after doing your stuff.
Now, for these reasons the rule is normally "avoid setlocale
, period"; but: we've been bitten several times in the past by the peculiar behavior of QCoreApplication
and derived classes; the documentation says:
On Unix/Linux Qt is configured to use the system locale settings by default. This can cause a conflict when using POSIX functions, for instance, when converting between data types such as floats and strings, since the notation may differ between locales. To get around this problem, call the POSIX function
setlocale(LC_NUMERIC,"C")
right after initializingQApplication
orQCoreApplication
to reset the locale that is used for number formatting to "C"-locale.
This behavior has been described in another question; my question is: what could be the rationale of this apparently foolish behavior? In particular, what's so peculiar about Unix and Linux that prompted such decision only on these platforms?
(Incidentally, will everything break if I just do setlocale(LC_ALL, "C");
after creating the QApplication
? If it's fine, why don't they just remove their setlocale(LC_ALL, "");
?)