解决方法
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-bitint
and the sign bit of the lowershort
is ignored when used in this 32-bitint
. Then,as a 32-bitsigned int
,there is a padding bit (in the middle of the 32 bits) that is ignored in determining the value 20 of the 32-bitsigned int
. But,if this 32-bit item is treated as a 32-bitunsigned 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,但会对性能造成损害无符号算术.