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

是否有任何现有的C实现具有(un)有符号整数表示中的填充位?

发布时间:2020-12-16 03:00:34 所属栏目:百科 来源:网络整理
导读:根据C99,签名int或unsigned int表示中可能有填充位.所以我不知道还有什么实现有这样的过时的东西吗? 解决方法 引用C99理由( PDF)第6.2.6.2节§20: Padding bits are user-accessible in an unsigned integer type. For example,suppose a machine uses a p
根据C99,签名int或unsigned int表示中可能有填充位.所以我不知道还有什么实现有这样的过时的东西吗?

解决方法

引用C99理由( PDF)第6.2.6.2节§20:

Padding bits are user-accessible in an unsigned integer type. For example,suppose a machine
uses a pair of 16-bit shorts (each with its own sign bit) to make up a 32-bit int and the sign bit of the lower short is ignored when used in this 32-bit int. Then,as a 32-bit signed int,there is a padding bit (in the middle of the 32 bits) that is ignored in determining the value 20 of the 32-bit signed int. But,if this 32-bit item is treated as a 32-bit unsigned int,then that padding bit is visible to the user’s program. The C committee was told that there is a machine that works this way,and that is one reason that padding bits were added to C99.

所以这样的事情至少确实存在.

至于奇怪的建筑still around today,例如UNIVAC 1100/2200系列及其weird data formats.

虽然它不使用整数填充,但是看看他们的C编译器手册(PDF)仍然是有启发性的:

Table 4–4. Size and Range of Unsigned Integer Types

Type                 Size        Range
unsigned short int   18 bits     0 to (2^18)–1
unsigned short

unsigned int         36 bits     0 to (2^36)–2 (see the following note)
unsigned

unsigned long int    36 bits     0 to (2^36)–2 (see the following note)
unsigned long

第二卷(PDF)解释了如何使用CONFORMANCE / TWOSARITH编译器关键字来控制负零的解释:这将无符号整数类型的范围调整为预期(2 ^ 36)-1,但会对性能造成损害无符号算术.

(编辑:李大同)

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

    推荐文章
      热点阅读