char size confusion(字符大小混乱)
问题描述
据我所知,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.
这篇关于字符大小混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:字符大小混乱


- Stroustrup 的 Simple_window.h 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- C++ 协变模板 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 近似搜索的工作原理 2021-01-01
- 从python回调到c++的选项 2022-11-16
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01