加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 09:23:09 所属栏目:百科 来源:网络整理
导读:根据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
根据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)来防止任何违反你假设的编译.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读