Exception problem with locale with g++ on Windows

Xi Ruoyao ryxi@stu.xidian.edu.cn
Tue Feb 21 05:54:00 GMT 2017


On 2017-02-20 20:33 +0100, Marvin Gülker wrote:

> Compare to the identical C program:
> 
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> #include <stdio.h>
> #include <locale.h>
> 
> int main()
> {
>   const char* str = setlocale(LC_ALL, "");
>   printf("Locale set to %s\n", str);
>   return 0;
> }
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> This program compiles and works as expected (on my system, it outputs
> "Locale set to German_Germany.1252").

They're not "identical". A better approximation is

~~~~~~~~~~
#include <stdio.h>
#include <locale.h>

int main()
{
    _locale_t locale = _create_locale(LC_ALL, "");
    strange_undocumented_set_global_locale(locale);
    _locale_t current_locale = _get_current_locale();
    printf("Locale is now: %s\n",
           strange_undocumented_get_locale_string(current_locale));
    _free_locale(locale);
    _free_locale(current_locale);
    return 0;
}
~~~~~~~~~~

These strange undocumented APIs make it difficult to implement
C++ Standard <locale> in Windows.

-- 
Xi Ruoyao <ryxi@stu.xidian.edu.cn>
School of Aerospace Science and Technology, Xidian University



More information about the Gcc-help mailing list