Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: UTF-8 and wchar_t

Thread Tools

Re: UTF-8 and wchar_t

Ersek, Laszlo
Posts: n/a
In article <(E-Mail Removed)>, Michal Nazarewicz <(E-Mail Removed)> writes:

> Also, what happens when I say to wprintf() a string which contains wide
> character which has no representation in current locale (ie. some funky
> unicode character where locale is set to ISO-8859-1 encoding)?

wprintf() will return a negative value [and errno will be set to EILSEQ].

> Can I somehow instruct the standard library function to print, say,
> a question mark in such situations or do I have to handle such cases by
> myself?

On a second thought, you might be better off if you converted the output
with iconv() too, from WCHAR_T to the codeset used by the current
If iconv() encounters a character in the input buffer that is valid, but
for which an identical character does not exist in the target codeset,
iconv() performs an implementation-dependent conversion on this

(You would have to test this.)

You should be able to get the codeset used by the current locale by


(Sorry for being glibc/SUSv2-specific.)

Reply With Quote
Mikko Rauhala
Posts: n/a
On Tue, 02 Mar 2010 21:42:07 +0100, Michal Nazarewicz <(E-Mail Removed)> wrote:
> Thanks for all the links and information. I have been considering
> iconv() but didn't notice that it can do conversion to/from wchar_t as
> well and that was my biggest concern. I'll be sure to look more into
> it.

To clarify further, it's not necessarily able to do so. The GNU
implementation does support it, but more generally, available
iconv sources/targets are implementation-defined.

> however depending on glibc may hurt me a bit as my code won't
> quite work on, say, BSD then.

Indeed I'm not sure if WCHAR_T is available for iconv there.
You can probably use GNU libiconv (under LGPL) there too if you like,

(Yeah, getting Unixy, sorry about that; if one continues further,
probably better to move to comp.unix.programming)

Mikko Rauhala <(E-Mail Removed)> -
The Finnish Pirate Party -
World Transhumanist Association -
Singularity Institute -
Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
converting from windows wchar_t to linux wchar_t C++ 3 08-15-2008 09:04 AM
Portable integer type which can hold int, wchar_t, and void * C Programming 3 05-15-2006 03:30 PM
wchar_t and wide characters C Programming 1 03-13-2006 01:16 PM
std::wstring, TCHAR, wchar_t and LPTSTR sorty C++ 4 11-25-2003 11:05 AM
string class that can convert between wchar_t and char Bren C++ 4 10-07-2003 03:24 PM