Hi guys, I have noticed that in mingw-gcc, the __FILE__ macro expands using the system's code page encoding (e.g. code page 936 on Simplified Chinese Windows systems). I will describe how it causes problems: When a mbcs literal is used in the source file, GCC does not check whether it is legal or not - it simply performs a bytewise copy, just opposite to MSVC, which converts UTF8 string literals to code page string literals. So the following code will work in both mingw-gcc and MSVC, when saved in ANSI text format: std::puts("喵"); // "\xDF\xF7" in CP936 But the following code will NOT work in GCC: std::fputws(L"喵", stdout); // L"\xDF\xF7" in CP936 GCC gives this error: error: converting to execution character set: Illegal byte sequence I believe this should be due to the encoding. When GCC finds a wide string literal, it tries to re-encode the string literal from the file into wide string format. In this progress GCC rejects any mbcs encoding but UTF8. Converting the source file encoding to UTF8 would solve this problem but will cause another one: most stdio functions still expects code page strings and will produce gibberish with UTF8 strings. The final sollution: avoid narrow string literals in source files, use wide string literals only. There is still a problem left: some ISO C macros such as __FILE__ still use code page encoding - the following code will produce compile errors if the file's name contains non-ASCII characters: #define TO_WCS2(x) L##x #define TO_WCS(x) TO_WCS2(x) std::fputws(TO_WCS(__FILE__), stdout); Personally I am considering this is a bug because GCC does not actually recognizes code page strings. What do you think about this?
Best regards, 2014-01-06 lh_mouse ------------------------------------------------------------------------------ Rapidly troubleshoot problems before they affect your business. Most IT organizations don't have a clear picture of how application performance affects their revenue. With AppDynamics, you get 100% visibility into your Java,.NET, & PHP application. Start your 15-day FREE TRIAL of AppDynamics Pro! http://pubads.g.doubleclick.net/gampad/clk?id=84349831&iu=/4140/ostg.clktrk _______________________________________________ Mingw-w64-public mailing list Mingw-w64-public@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/mingw-w64-public