Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between glib gunichar and wchar_t and which is better for cross-platform solutions?

I'm trying to write some C code which is portable only so far as the user has gcc, and has glib installed.

From all my research, I've found that with gcc, a wchar_t is always defined as 4 bytes, and with glib a gunichar is also 4 bytes.

What I haven't figured out is if like a gunichar, a wchar_t is encoded as UCS4 as well. Is this the case? If so, I should be able to simply cast a gunichar* to a wchar_t* and use the stdc wcs* functions, right?

like image 554
ckot Avatar asked Mar 24 '12 09:03

ckot


1 Answers

If you use GLib, don't use wchar_t. Use its unicode support, it's a lot better than the C standard library's support.

wchar_t is 4 bytes on Linux and Mac OS (and a few others), not on Windows (it's 2 bytes there) and some others. Portable code means avoiding wchar_t like the plague.

like image 183
rubenvb Avatar answered Sep 20 '22 06:09

rubenvb