C99的整型提升规则提到,当int能够代表原(整型)类型的所有值时,原类型转换为int类型,否则转换为unsigned int。
If an int can represent all values of the original type, the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions. All other types are unchanged by the integer promotions.
不太理解例外的情况(转换为unsigned int的情况),可否举例说明?
在部分计算机上,
int和short的大小都是16位(C语言标准只规定了这两个类型的最小大小为16位)。若此时将一个unsigned short的变量进行整型提升,便只能提升到unsigned int。