找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 727|回复: 1

Question8.10:I'm starting to think about multinational character sets。。。

[复制链接]

210

主题

371

回帖

0

积分

管理员

积分
0
发表于 2013-7-1 14:06:12 | 显示全部楼层 |阅读模式
Q: I'm starting to think about multinational character sets, and I'm worried about the implications of making sizeof(char) be 2 so that 16-bit character sets can be represented.
A: If type char were made 16 bits, sizeof(char) would still be 1, and CHAR_BIT in <limits.h> would be 16, and it would simply be impossible to declare (or allocate with malloc) a single 8-bit object.

Traditionally, a byte is not necessarily 8 bits, but merely a smallish region of memory, usually suitable for storing one character. The C Standard follows this usage, so the bytes used by malloc and sizeof can be more than 8 bits.

To allow manipulation of multinational character sets without requiring an expansion of type char, ANSI/ISO C defines the ``wide&#39;&#39; character type wchar_t, and corresponding wide string literals, and functions for manipulating and converting strings of wide characters.

See also question 7.8.

210

主题

371

回帖

0

积分

管理员

积分
0
 楼主| 发表于 2013-7-1 14:35:59 | 显示全部楼层
问题:我开始考虑多国的字符集的问题,我想将sizeof(char)定义为2,那么16位字符集就可以被表示了。
回答:如果char型被认为是16位,sizeof(char)将仍然为1,并且CHAR_BIT在<limits.h>中为16。那么将不可能声明(或者是用malloc分配)一个简单的8位对象了。
传统上,一个字节并不一定必须是8位,它仅仅是内存中的一小段区域,经常用来存储一个字符的大小。标准C也使用了这种用法,因此malloc和sizeof都可以使用的字节都是8位以上。
为了允许在没有扩展字符类型的情况下操作多国的字符集,ANSI/ISO C定义了“宽”字符型wchar_t,和相应的宽字符串,以及用来操作和转换宽字符串的函数。
参考问题7.8。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

果子博客
扫码关注微信公众号

Archiver|手机版|小黑屋|风叶林

GMT+8, 2026-2-1 16:59 , Processed in 0.081858 second(s), 20 queries .

Powered by 风叶林

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表