gpt4 book ai didi

c - 什么是字节?

转载 作者:太空宇宙 更新时间:2023-11-04 06:48:53 25 4
gpt4 key购买 nike

C 标准在许多不同的地方使用字节这个词。大多数情况下,它与我对这个词的理解非常相似 - 8 位长的数据 block 。

但是:

The sizeof operator yields the size (in bytes) of its operand

和:

When sizeof is applied to an operand that has type char, unsigned char, or signed char, (or a qualified version thereof) the result is 1

后来:

When applied to an operand that has array type, the result is the total number of bytes in the array.

因此,如果我们考虑具有超过 8 位的 char 的机器,则该程序的可观察行为将不同于 8 位 char 机器。

char foo[5];

for(size_t index = 0; index < sizeof(foo) / sizeof(char); index++)
{
/* some code */
}

所以可能字节含义在C标准理解上是不同的。谁能解释一下:字节是 8 位还是字节是不同的东西

还有一个问题。

sizeof(char) == sizeof(array[0])吗?考虑字节大小差异

最佳答案

3. Terms, definitions, and symbols

3.6 byte addressable unit of data storage large enough to hold any member of the basic character set of the execution environment

NOTE 1 It is possible to express the address of each individual byte of an object uniquely.

NOTE 2 A byte is composed of a contiguous sequence of bits, the number of which is implementation- defined. The least significant bit is called the low-order bit; the most significant bit is called the high-order bit.

根据 C 标准,这是一个字节。它的最小大小只是保存执行环境的基本字符集所需的位数,即现在 IIRC 最少 8 位。以位为单位的字节的确切大小在 CHAR_BIT 宏中编码。

关于c - 什么是字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54275447/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com