积分促销

问题描述:

当它是有史以来一个符号整数无法重新present原始类型的所有值与问候整型提升的情况下?

When is it ever the case that a signed integer cannot represent all the values of the original type with regards to integer promotion?

从文字K&安培; R,C语言程序设计,第二版。页。 174

From the text K&R, C Programming Language, 2nd Ed. p. 174

A.6.1积分促销

一个字,短整数或整数位字段,所有符号或没有,或枚举类型的对象,可在使用
  前pression随时随地可以使用一个整数。 如果int可以重新present
  原始类型的所有值,则该值转换为
  INT;否则,值转换为unsigned int类型
即可。这个过程
  被称为整体提升。

A character, a short integer, or an integer bit-field, all either signed or not, or an object of enumeration type, may be used in an expression wherever an integer may be used. If an int can represent all the values of the original type, then the value is converted to int; otherwise the value is converted to unsigned int. This process is called integral promotion.

这code显示类型我的系统的限制:

This code shows the limits of the types for my system:

#include <stdio.h>
#include <limits.h>

int main(void)
{

    printf("CHAR_MAX: %i\n", CHAR_MAX);     
    printf("UCHAR_MAX: %i\n", UCHAR_MAX);

    printf("SHORT_MAX: %i\n", SHRT_MAX);        
    printf("USHORT_MAX: %i\n", USHRT_MAX);

    printf("INT_MAX: %i\n", INT_MAX);       
    printf("UINT_MAX: %u\n", UINT_MAX);

    return 0;
}

的结果是:

CHAR_MAX: 127
UCHAR_MAX: 255
SHORT_MAX: 32767
USHORT_MAX: 65535
INT_MAX: 2147483647
UINT_MAX: 4294967295

签署的整型比任何其他类型的方式做大,因此,当将它曾经回落到UINT_MAX?

The signed int type is way bigger than any of the other types, so when would it ever fall back to UINT_MAX?

这有可能为短整型是大小为同一 INT ,所以一个无符号的短整型无法晋升到 INT ,例如。这恰恰是不是你的编译器的情况下。

It's possible for a short int to be the same size as an int, so an unsigned short int could not be promoted to an int, for example. This just isn't the case on your compiler.