donet8 发表于 2012-03-19 13:02

是不是所有的体系结构都是"有符号数+无符号数=无符号数"?

有没有什么逻辑上的必然性说,不管一个体系结构如何实现,都必须要
"有符号数+无符号数=无符号数"这样实现呢?

EricFisher 发表于 2012-03-19 14:43

C语言标准里规定了如何进行类型转换,挺繁琐的,需要看具体的操作数类型,以及转换级别(integer conversion rank),我把这段英文贴出来,感兴趣的可以看看。

Otherwise, the integer promotions are performed on both operands. Then the
following rules are applied to the promoted operands:
If both operands have the same type, then no further conversion is needed.

Otherwise, if both operands have signed integer types or both have unsigned
integer types, the operand with the type of lesser integer conversion rank is
converted to the type of the operand with greater rank.

Otherwise, if the operand that has unsigned integer type has rank greater or
equal to the rank of the type of the other operand, then the operand with
signed integer type is converted to the type of the operand with unsigned
integer type.

Otherwise, if the type of the operand with signed integer type can represent
all of the values of the type of the operand with unsigned integer type, then
the operand with unsigned integer type is converted to the type of the
operand with signed integer type.

Otherwise, both operands are converted to the unsigned integer type
corresponding to the type of the operand with signed integer type.

页: [1]
查看完整版本: 是不是所有的体系结构都是"有符号数+无符号数=无符号数"?