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

前端之家收集整理的这篇文章主要介绍了是否有任何现有的C实现具有(un)有符号整数表示中的填充位?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_403_0@
根据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,但会对性能造成损害无符号算术.

原文链接:https://www.f2er.com/c/112741.html

猜你在找的C&C++相关文章