是CHAR_BIT = 4 C标准授权的可能值? [英] Is CHAR_BIT=4 a possible value authorized by the C standard?

查看:87
本文介绍了是CHAR_BIT = 4 C标准授权的可能值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我考虑一个非常具体的(与时下没用)处理器,称为土星

I'm considering a very specific (and nowadays useless) processor, called saturn.

其中该CPU的奇怪的特性之一是,其元件单元是半字节(4位),而不是字节(8位)。这不只是化妆品,任何指针的值是在蚕食pssed前$ P $。

One of the strange feature of this CPU is that its element unit is the nibble (4-bits), not the byte (8-bits). It's not just cosmetic, any pointer value is expressed in nibble.

有是创造了土星C编译器一次尝试: hp48xgcc

There was one attempt at creating a C compiler for Saturn : hp48xgcc

综观其文档,我注意到,它的基本类型按照通常的惯例GCC与烧焦8位。在这一点上,我想知道:
这难道不是CHAR_BIT打算提供元件单元的大小?
这似乎是由 GCC自己的文档上暗示

Looking at its documentation, I noticed that its basic types follow the usual GCC convention, with char 8 bits. At this point, I wondered : Is it not the intention of CHAR_BIT to provide the size of the element unit ? This seems to be hinted by GCC own documentation :

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

在此情况下,考虑到土星的架构,这将是最好有CHAR_BIT = 4

In this case, considering the Saturn architecture, it would be better to have CHAR_BIT = 4

还是我误解CHAR_BIT的意义?

Or do I misunderstand the signification of CHAR_BIT ?

推荐答案

没有。根据C99标准的 CHAR_BIT最小值为8 (顺便说一句,这是事实也是C89 / 90)。

No. According to C99 standard CHAR_BIT minimum value is 8 (BTW, this is true also for C89/90).

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

The relevant section of the C99 draft standard (WG14/N1256) is the following:

下面给出的值应以适合在#if使用前不变pressions被替换
  preprocessing指令。此外,除了CHAR_BIT和MB_LEN_MAX,所述
  下列事项应由具有相同类型的会前pressions被替换
  前pression是根据整数变换的相应类型的对象
  促销。他们实现定义的值应是大小相等或更大
  (绝对值)的那些中所示,使用相同的符号。

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

这篇关于是CHAR_BIT = 4 C标准授权的可能值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆