Integer promotion 的例外情况?

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的情况),可否举例说明?

阅读 1.8k
1 个回答

在部分计算机上,intshort的大小都是16位(C语言标准只规定了这两个类型的最小大小为16位)。若此时将一个unsigned short的变量进行整型提升,便只能提升到unsigned int

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进