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.
这篇关于字符大小混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:字符大小混乱
基础教程推荐
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- 从 std::cin 读取密码 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07