字符大小混乱
据我所知,1 char = 1 byte = 8 bits(32 位系统).
As per I know that 1 char = 1 byte = 8 bits(32 bit system).
char c=0xffff0000; //wrong
那么为什么 char
只允许 8 位 以及文件中的每个字符也是 8 位 长度.
then why char
allow just 8 bits and also every character in a file also of 8 bit length.
谢谢.
推荐答案
没有.char的sizeof定义为1.但这并不意味着它总是占用32位/8位.
No. The sizeof char is by definition 1. But this does not mean that it occupies 32-bits/8-bits always.
$3.9.1/1-声明为字符(char)的对象应该很大足以存储任何成员实现的基本字符集."
$3.9.1/1- "Objects declared as characters (char) shall be large enough to store any member of the implementation’s basic character set."
字节是 8 位似乎令人困惑.然而,C++ 标准并没有强制要求这样做.
There appears to be a confusion that a byte is 8-bits. The C++ Standard does not mandate this however.
这是标准 $1.7/1 中定义字节的方式
Here's how byte is defined in the Standard $1.7/1
C 中的基本存储单元++内存模型是字节.一个字节至少大到足以包含基本执行的任何成员字符集,由一个连续的位序列,其中的数量是实现定义.
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 is composed of a contiguous sequence of bits, the number of which is implementation-defined.
很明显,一个字节不必总是 8 位.
As is clear, a byte need not be always 8-bits.
相关文章