[BUG] wprintf(L"%s", str) expects str to be wide
Konstantin Isakov
ikm@goldendict.org
Fri Jan 11 06:58:00 GMT 2013
Hi,
This works as expected in glibc:
#include <stdio.h>
wprintf(L"Hello, %s\n", "world");
However, the same thing does not work correctly in newlib. Instead, this works:
wprintf(L"Hello, %s\n", L"world");
I believe "%s" should always expect a narrow 8-bit string,
irrespective of the wideness of printf. "%ls" should be used for wide
strings. Newlib seems to interpret "%s" as wide for wide printfs,
which doesn't seem to be correct.
man wprintf:
s If no l modifier is present: The const char * argument is
expected to be a pointer to an array of character type (pointer
to a string) containing a multibyte character sequence beginning
in the initial shift state. Characters from the array are con‐
verted to wide characters (each by a call to the mbrtowc(3)
function with a conversion state starting in the initial state
before the first byte). The resulting wide characters are writ‐
ten up to (but not including) the terminating null wide charac‐
ter. [..]
(This is with newlib 1.20.0)
More information about the Newlib
mailing list