On 2/12/2016 10:14 PM, J Decker wrote:
> mbstowcs( out, utf8, 5 );

mbstowcs expects the string in the codepage of the current locale - 
which is never UTF-8.

> for( n = 0; n < 5; n++ )
> printf( "%04x ", out[n] );  // output is 00f0 0090 0080 0081; expect d800 dc01

Why do you expect that? It appears your system uses Western European 
codepage (aka Latin-1). You pass a character "\xf0" which, when taken to 
be encoded in that codepage, is quite properly converted to U+00F0.

> for( n = 0; n < 5; n++ )
>        printf( "%02x ", chout[n] );  // output is 00 00 00 00

U+10001 is (unsurprisingly) not representable in your current ANSI 
codepage, so wcstombs call fails (I can't help but notice that you 
aren't checking any calls for failure) and leaves the output buffer 
unchanged.

> so it does no useful conversion either way :)

It performs the conversion it is documented to perform. It indeed 
doesn't perform the conversion that you, for reasons unclear, expect it 
to perform. In other words, you engage in wishful thinking, and then 
blame the messenger for failure of your wishes to materialize.
-- 
Igor Tandetnik

Reply via email to