- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
根据 N4140
(C++11 工作草案):
The fundamental storage unit in the C ++ memory model is the byte. A byte is at least large enough to contain any member of the basic execution character set and the eight-bit code units of the Unicode UTF-8 encoding form and is composed of a contiguous sequence of bits, the number of which is implementation-defined. (§6.6.1-1; p.48)
我认为只需要 8 位来包含“Unicode UTF-8 编码形式的八位代码单元”的所有成员。是否还需要更多位来包含“基本执行字符集”的所有成员?为什么CHAR_BIT
在很多实现中可以是8?
最佳答案
基本执行字符定义如下(强调我的):
The basic execution character set and the basic execution wide-character set shall each contain all the members of the basic source character set, plus control characters representing alert, backspace, and carriage return, plus a null character (respectively, null wide character), whose value is 0. For each basic execution character set, the values of the members shall be non-negative and distinct from one another. In both the source and execution basic character sets, the value of each character after 0 in the above list of decimal digits shall be one greater than the value of the previous. The execution character set and the execution wide-character set are implementation-defined supersets of the basic execution character set and the basic execution wide-character set, respectively. The values of the members of the execution character sets and the sets of additional members are locale-specific.
基本源字符集是这样的:
The basic source character set consists of 96 characters: the space character, the control characters representing horizontal tab, vertical tab, form feed, and new-line, plus the following 91 graphical characters:
a b c d e f g h i j k l m n o p q r s t u v w x y z
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
0 1 2 3 4 5 6 7 8 9
_ { } [ ] # ( ) < > % : ; . ? * + - / ^ & | ~ ! = , \ " '
请注意标准定义的基本执行字符集与实现定义的执行字符集之间的区别。前者仅包含大约 100 个字符,而那些(无论是哪个)的编码可以很好地适应 8 位。
在阅读问题中的段落时,还必须谨慎行事。一个字节需要足够大以容纳基本执行字符集中的字符编码或 utf-8 字符。前一种编码可能(通常是)是后者的子集,但即使不一定是,8 位也足够了。
关于c++ - 为什么 CHAR_BIT 通常是 8?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49766777/
我对 limit.h 中的 CHAR_BIT 感到困惑。我读过一些文章说宏 CHAR_BIT 是为了可移植性。在代码中使用宏而不是像 8 这样的魔数(Magic Number),这是合理的。但是lim
CHAR_BIT 定义每个字符的位数。但它是一个旧的宏。类似的宏已在最近的 C++ 标准中被替换。 C++11/14/17 中是否有更现代的 CHAR_BIT 替代品? 最佳答案 非符号位数由 std
引用计算整数绝对值 (abs) 的代码而不从 http://graphics.stanford.edu/~seander/bithacks.html 分支: int v; // w
我只是 checking an answer并意识到 CHAR_BIT没有像我期望的那样由标题定义,甚至没有 #include , 在较新的 GCC 上。 我真的需要#include 只是为了获得
我有一个用 C 语言实现的位 vector ,我想避免除法和模数运算,并用(更快的)位运算替换它们。因此,我将位放入字节(字符)中,并需要索引到这些数组中,然后取出一些位。我的实现如下所示: #inc
ISO C 标准要求 CHAR_BIT 至少为 8。 POSIX 要求 CHAR_BIT 等于 8,并且(几乎?)所有使用 octets 的网络和通信标准,是否有任何当代C 实现,其中 CHAR_BI
根据 N4140(C++11 工作草案): The fundamental storage unit in the C ++ memory model is the byte. A byte is a
似乎没有任何库函数可以计算类型的位大小。 我认为这可以通过以下方式完成吗? #include template size_t Size_In_Bits(){ return sizeof(T
在 Tanenbaum 的操作系统设计和实现中,第 154 页说位图中的每个 NR_SYS_PROCS(32) 都有一个位。 并且在 minix/kernel/table.c 的末尾,有一个检查以确保
在 POSIX 基本原理中有一个说明,强制 CHAR_BIT 为 8 是为了保持与 C99 的一致性而不丢弃套接字/网络所必需的让步,但我从来没有看到冲突到底是什么的解释。有没有人有轶事或引文说明为什
我正在考虑一个非常特殊的(现在没用的)处理器,叫做 saturn . 这个 CPU 的一个奇怪特征是它的元素单位是半字节(4 位),而不是字节(8 位)。这不仅仅是装饰性的,任何指针值都以半字节表示。
我手边没有任何带有 CHAR_BIT > 8 的平台。 所以我更改了文件limits.h中的相关预处理器定义: #define CHAR_BIT 16 /* number
1.请考虑以下事项: unsigned int a, b; b = a >> ((sizeof a) * CHAR_BIT); /* or 2nd operand greater than ((siz
如果目标系统上的 CHAR_BIT == 8(大多数情况下),则很容易屏蔽掉单个字节: unsigned char lsb = foo & 0xFF; 但是,在一些系统和 C 实现中,CHAR_BIT
如果目标系统上的 CHAR_BIT == 8(大多数情况下),则很容易屏蔽掉单个字节: unsigned char lsb = foo & 0xFF; 但是,在一些系统和 C 实现中,CHAR_BIT
在 C99 的 7.19.7.1 节中,我们有: If the end-of-file indicator for the input stream pointed to by stream is n
C# 是否有类似于 C++ 的 CHAR_BIT 的东西? ? 更新: 基本上,我试图在没有分支的情况下计算 abs,这是 C++ 版本: // Compute the integer absolut
是否存在机器(或编译器),其中 sizeof(char) != 1? C99 标准 是否规定sizeof(char) 在标准合规性实现中必须正好为 1?如果有,请给我章节编号和引用。 更新:如果我有一
我是一名优秀的程序员,十分优秀!