_configthreadlocale and localeconv

穿精又带淫゛_ 提交于 2019-12-10 19:09:59

问题


As we all know, global data, like the locale settings affecting the numeric decimal point printf() and strtod() are using, is evil. Fortunately, MSVC++ 9 allows to use per-thread locales by a _configthreadlocale(_ENABLE_PER_THREAD_LOCALE) call. Unfortunately, it seems that the localeconv() function does not notice this and still returns the global locale settings, e.g. localeconv()->decimal_point seems to always return the global locale setting before the _configthreadlocale() call. Is this a bug in the MSVC library or is this expected?

TIA Paavo


回答1:


Despite the suggestion that this is expected behaviour from rubenvb, this is actually a bug that I ran into a while ago. I suspect rubenvb misread this part of the question:

Unfortunately, it seems that the localeconv() function does not notice this and still returns the global locale settings, e.g. localeconv()->decimal_point seems to always return the global locale setting before the _configthreadlocale() call.

The question wasn't intending on having localeconv() return on a per-thread basis before calling _configthreadlocale() as that would break the time continuum. The question was suggesting that the results of calling localeconv() after calling _configthreadlocale() are the same as calling it beforehand, which is unexpected. This essentially means Microsofts implementation of the C++ STL streams are fundamentally broken when using _configthreadlocale().




回答2:


The call to the _configthreadlocale sets the property, before the call, nothing special happens. So yes, this is expected behavior. You first must call this function, and then you can take advantage of thread-local locales.



来源:https://stackoverflow.com/questions/276030/configthreadlocale-and-localeconv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!