wchar_t的在Linux上的UTF-16? [英] wchar_t for UTF-16 on Linux?

查看:578
本文介绍了wchar_t的在Linux上的UTF-16?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这有什么意义使用 wchar_t的* 在Linux上存储UTF-16连接codeD文字?最明显的问题是, wchar_t的是在Linux和UTF-16四个字节通常需要两个(或有时两两组)每字符字节。

Does it make any sense to store UTF-16 encoded text using wchar_t* on Linux? The obvious problem is that wchar_t is four bytes on Linux and UTF-16 takes usually two (or sometimes two groups of two) bytes per character.

我试图使用第三方库,正是如此,它似乎非常混乱。看起来事情搞砸,因为在Windows wchar_t的是两个字节,但我只是想仔细检查,因为这是一个pretty昂贵的商业库,可能是我只是不不懂的东西。

I'm trying to use a third-party library that does exactly that and it seems very confusing. Looks like things are messed up because on Windows wchar_t is two bytes, but I just want to double check since it's a pretty expensive commercial library and may be I just don't understand something.

推荐答案

虽然可以存储UTF-16 wchar_t的,例如 wchar_t的值(或作为字符串其中数组)不适合与任何的 wchar_t的的标准功能,这需要或指针使用,以 wchar_t的字符串。因此,要回答你的是否有意义......最初的问题,我会明确的没有回答。你可以使用 uint16_t 用于此目的当然还是C11 char16_t ,如果它是可用的,但我看不出有什么之所以后者将是preferable除非你还打算使用C11功能处理它(他们似乎不被尚未实现)。

While it's possible to store UTF-16 in wchar_t, such wchar_t values (or arrays of them used as strings) are not suitable for use with any of the standard functions which take wchar_t or pointers to wchar_t strings. As such, to answer your initial question of "Does it make sense...?", I would reply with a definitive no. You could use uint16_t for this purpose of course, or the C11 char16_t if it's available, though I fail to see any reason why the latter would be preferable unless you're also going to use the C11 functions for processing it (and they don't seem to be implemented yet).

这篇关于wchar_t的在Linux上的UTF-16?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆