On 2017/11/9 12:13, David Lee wrote:
Hello. I have an issue that isn't necessarily related to mingw-w64.
Could be gcc/g++, libstdc++ or even my mistake. Let me have a starting
point here.

(... abridged ...) >
[Question] Did I do something wrong or is the issue not related to
mingw-w64? (it looks like a libstdc++ problem, since cstdio and cwchar
are C++ headers, but I am not sure).

Thanks.


That is because <cwchar> and <cstdio> (and perhaps most of others) from libstdc++ define `__USE_MINGW_ANSI_STDIO` unconditionally.

See /<prefix>/include/c++/<version of gcc>/<triplet>/bits/os_defines.h .
On my computer this file is located at C:/MinGW/MSYS2/mingw64/include/c++/7.2.1/x86_64-w64-mingw32/bits/os_defines.h.

The C99 standard says `%s` in *printf format strings corresponds to a `char *` and it is `%ls` that corresponds to a `wchar_t *`, which contradicts MS's specification, in which `%s` corresponds to the same type as the destination string and `%S` corresponds to the other. So in your last two examples the two wide strings are interpreted as narrow ones. Since x86 is little-endian, L"Hello" has the same byte representation as "H\0e\0l\0l\0o\0", excluding both null terminators, which contains only one character before its terminator.

--
Best regards,
LH_Mouse


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Mingw-w64-public mailing list
Mingw-w64-public@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mingw-w64-public

Reply via email to