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

假装没事ソ 提交于 2020-01-02 04:07:21

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/9850553/whats-the-difference-between-glib-gunichar-and-wchar-t-and-which-is-better-for

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!