#1559 Localized message may not appear on Windows 7

Wu Yongwei

When a user uses the default encoding on Chinese Windows, or set the encoding to Chinese on English Windows, he will probably not see the correct localized message under Windows 7. An analysis is put here:


In short, Windows 7 changed the behaviour of the I/O functions in MSVCRT.DLL. While the test program can output 6 identical lines under Windows XP, if the console code page is 936 (Simplified Chinese), only three can output the wanted messages under Windows 7.

The new rules seem to be:

1) The I/O functions output characters verbatim when the LC_CTYPE is C (the default).
2) The I/O functions convert the characters from the locale to the code page when the LC_CTYPE specifies a code page.
3) The single-byte functions (putchar, fputc, etc.) do not output multi-byte characters when the locale is in a double-byte character set (DBCS).
4) The I/O functions behave the XP way (no conversion of any kind) if the output is redirected to a file.

The GCC behaviour implies that it calls setlocale(LC_ALL, ""); or setlocale(LC_CTYPE, "");, and uses single-byte functions to output the message. One of the following method should fix this issue:

1) Insert a setlocale(LC_CTYPE, "C") call after other setlocale calls to stop the autoconversion.
2) Output the multi-byte characters together instead of one byte at a time.


  • Wu Yongwei

    Wu Yongwei - 2011-06-23

    Test program to show the I/O difference between Windows 7 and Windows XP

  • Earnie Boyd

    Earnie Boyd - 2013-02-08
    • labels: gcc --> gcc, locale, code page, duplicate?
    • milestone: --> OTHER
    • type: --> Task
    • resolution: --> none
    • category: --> Unknown
    • patch_attached: --> False

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks