gpt4 book ai didi

c - CHAR_BIT=4 是 C 标准授权的可能值吗?

转载 作者:太空狗 更新时间:2023-10-29 15:45:05 24 4
gpt4 key购买 nike

我正在考虑一个非常特殊的(现在没用的)处理器,叫做 saturn .

这个 CPU 的一个奇怪特征是它的元素单位是半字节(4 位),而不是字节(8 位)。这不仅仅是装饰性的,任何指针值都以半字节表示。

曾经有人尝试为 Saturn 创建 C 编译器:hp48xgcc

查看其 documentation ,我注意到它的基本类型遵循通常的 GCC 约定,char 8 位。在这一点上,我想知道:CHAR_BIT 的本意不是提供元素单元的大小吗?GCC own documentation 似乎暗示了这一点:

You can compute the number of bits in any data type like this:
sizeof (type) * CHAR_BIT

在这种情况下,考虑到 Saturn 架构,最好让 CHAR_BIT = 4

还是我误解了 CHAR_BIT 的含义?

最佳答案

没有。根据 C99 标准,CHAR_BIT 最小值为 8(顺便说一句,对于 C89/90 也是如此)。

C99标准草案(WG14/N1256)的相关部分如下:

5.2.4.2.1 Sizes of integer types

The values given below shall be replaced by constant expressions suitable for use in #if preprocessing directives. Moreover, except for CHAR_BIT and MB_LEN_MAX, the following shall be replaced by expressions that have the same type as would an expression that is an object of the corresponding type converted according to the integer promotions. Their implementation-defined values shall be equal or greater in magnitude (absolute value) to those shown, with the same sign.

— number of bits for smallest object that is not a bit-field (byte)

CHAR_BIT             8

关于c - CHAR_BIT=4 是 C 标准授权的可能值吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18537747/

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