延斯,保罗和妇幼保健,
感谢您的澄清。但根据“ISO/IEC 9899第6.3.1.1节
The rank of any unsigned integer type shall equal the rank of the corresponding
signed integer type, if any.
和根据6.3.1.8通常的算术转换”下列规则应适用。
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
所以根据上述规则符号的短(整数型)3第一应被转换为无符号短(整数型),然后arithmatic操作应被执行和结果应当是0xF2。
不会编译。 'Temp2'未定义。 – 2014-12-02 13:22:49
在进行数学计算之前'Temp'和'(unsigned short)Temp2'都被提升为int。 C中的操作不能在小于int的类型中完成 – 2014-12-02 15:55:44
@LưuVĩnhPhúc在进行数学运算之前,'(unsigned short)Temp2'被提升为int或unsigned。这取决于类型的范围。 – chux 2014-12-02 19:18:54