Yes. Both are equal to CHAR_BIT
*.
C标准定义CHAR_BIT
as: “不是位字段(字节)的最小对象的位数”。 c99 明确表示:“一个字节包含CHAR_BIT
bits."
"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
需要at most CHAR_BIT
bits (char_bits <= CHAR_BIT
).
From char_bits >= CHAR_BIT
and char_bits <= CHAR_BIT
接下来char_bits == CHAR_BIT
(无填充位)。
POSIX 明确表示: "CHAR_BIT
类型中的位数char
."
*: 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 草案中):"signed char
不得有任何填充位。应该只有一个符号位。”
From $6.2.5.15
:
实施应定义char
具有相同的范围,
代表和行为signed char
or unsigned char
它遵循:全部CHAR_BIT
位用于表示CHAR_MIN..CHAR_MAX
范围(因为两者signed
and unsigned char
类型使用所有位)。
为了比较,不同于char
; _Bool
可以使用更少的位$6.7.2.1.4(122)
:
虽然a中的位数_Bool
对象至少是CHAR_BIT
,a 的宽度(符号位和值位的数量)_Bool
可能只是1 bit.