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.
这篇关于字符大小混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:字符大小混乱
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
