当前位置 : 主页 > 编程语言 > c++ >

c – GCC编译器的字节数为多少位

来源:互联网 收集:自由互联 发布时间:2021-06-23
根据C规范 A byte is at least large enough to contain any member of the basic execution character set (2.3) and the eight-bit code units of the Unicode UTF-8 encoding form and is composed of a contiguous sequence of bits, the number of w
根据C规范

A byte is at least large enough to contain any member of the basic
execution character set (2.3) and the eight-bit code units of the
Unicode UTF-8 encoding form and is composed of a contiguous sequence
of bits, the number of which is implementation defined.

这意味着,一个字节中的位数必须是8位或大于8位.

现在,根据gcc,比特数由ABI确定.

https://gcc.gnu.org/onlinedocs/gcc-5.4.0/gcc/Characters-implementation.html#Characters-implementation

4.4字符

字节中的位数(C90 3.4,C99和C11 3.6).

由ABI决定

GCC基于ABI-http://itanium-cxx-abi.github.io/cxx-abi/

有人能指出我提到一个字节中的位数的位置吗?

C标准(因此大多数编译器)有效地仅保证char至少为8个连续位.对于任何特定编译,实际位数取决于目标CPU架构.

但是,在大多数情况下,您必须非常努力地找到没有8位字节的目标CPU.

如果你必须编写依赖于8位字节假设的代码,那么你总是可以使用static_assert(CHAR_BIT == 8)来防止任何违反你假设的编译.

网友评论