是位在一个字节等于位在char类型的数量有多少? [英] Is the number of bits in a byte equal to the number of bits in a type char?
问题描述
请问C标准的任务呢?是否有一个平台,在这里位的字节数量不是一个类型字符
?
Does C standard mandates it? Is there a platform where the number of bits in a byte is not equal to the number of bits in a type char
?
推荐答案
是的。两者都等于 CHAR_BIT
* 。
C标准定义 CHAR_BIT
如:为最小物体位数不是一个位域(字节)的。 C99明确地说: 一个字节包含 CHAR_BIT
位。的
C standard defines CHAR_BIT
as: "number of bits for smallest object that is not a bit-field (byte)". c99 says explicitly: "A byte contains CHAR_BIT
bits."
的 UCHAR_MAX
应等于2 CHAR_BIT
- 1 - 这意味着 unsigned char型
需要的至少 CHAR_BIT
位( char_bits> = CHAR_BIT
)
"UCHAR_MAX
shall equal 2CHAR_BIT
- 1" — it means unsigned char
requires at least CHAR_BIT
bits (char_bits >= CHAR_BIT
).
的sizeof(char)的== 1
(单字节字符一个字节适合),即键入字符
需要的最多 CHAR_BIT
位( char_bits< = CHAR_BIT
)。
sizeof(char) == 1
(single-byte character fits in a byte) i.e., type char
requires at most CHAR_BIT
bits (char_bits <= CHAR_BIT
).
从 char_bits&GT; = CHAR_BIT
和 char_bits&LT; = CHAR_BIT
得出 char_bits == CHAR_BIT
(无填充位)。
From char_bits >= CHAR_BIT
and char_bits <= CHAR_BIT
follows that char_bits == CHAR_BIT
(no padding bits).
POSIX说,它明确地:在 中键入字符
位的 CHAR_BIT
的数量。的
* :如果字符
签署和 CHAR_BIT&GT; 8
然后(不包括 $ 6.2.6.2
下面引号),目前还不清楚是否 SCHAR_MIN..SCHAR_MAX
范围涵盖了所有的 CHAR_BIT
位。虽然名称 CHAR_BIT
明确传达的意图(位在字符
号)。
*: If char
is signed and CHAR_BIT > 8
then (without the $6.2.6.2
quote below) it was not clear whether SCHAR_MIN..SCHAR_MAX
range covers all CHAR_BIT
bits. Though the name CHAR_BIT
communicates the intent clearly ("number of bits in char
").
C11说( $ 6.2.6.2
在n1570草案)的符号字符
不得有任何填充位。应当有只有一个符号位。的
c11 says ($6.2.6.2
in n1570 draft): "signed char
shall not have any padding bits. There shall be exactly one sign bit."
从 $ 6.2.5.15
:
的实施应确定字符
具有相同的范围内,
再presentation和行为,无论是符号字符
或 unsigned char型
The implementation shall define
char
to have the same range, representation, and behavior as eithersigned char
orunsigned char
它遵循:所有的 CHAR_BIT
位被用来重新present CHAR_MIN..CHAR_MAX
范围(因为无论签署
和 unsigned char型
键入使用的所有位)。
it follow: All CHAR_BIT
bits are used to represent CHAR_MIN..CHAR_MAX
range (because both signed
and unsigned char
type use all bits).
为了比较,不像字符
; _Bool
可以使用更少的位 $ 6.7.2.1.4(122)
:
For comparison, unlike char
; _Bool
may use less bits $6.7.2.1.4(122)
:
虽然位在 _Bool
对象的数量至少为 CHAR_BIT
宽度(符号和数值的位数)一个 _Bool
可能只是 1位
While the number of bits in a
_Bool
object is at leastCHAR_BIT
, the width (number of sign and value bits) of a_Bool
may be just 1 bit.
这篇关于是位在一个字节等于位在char类型的数量有多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!