c - C 中的整数提升会降级 `long int` 吗?

标签 c

来自C standard

6.3.1.1

If an int can represent all values of the original type (as restricted by the width, for a bit-field), the value is converted to an int; otherwise, it is converted to an unsigned int. These are called the integer promotions.

所以这意味着如果我在表达式中使用 long int,它将被降级为 unsigned int

最佳答案

您引用的位受其上方文本的限制:

The following may be used in an expression wherever an int or unsigned int may be used:

  • An object or expression with an integer type whose integer conversion rank is less than the rank of int and unsigned int.
  • A bit-field of type _Bool, int, signed int,or 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.

换句话说,long int 不会被提升为 intunsigned int

关于c - C 中的整数提升会降级 `long int` 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14994728/

相关文章:

c - 如何控制数组的长度

c - 通过 socket tcp 发送一个带有空格的字符串

c - 将类型发送到函数并读取特定数据类型

c++ - 堆栈问题

c - 在 C 编程方面需要一些帮助

c - 需要有关以下代码的输出的帮助,并在可能的情况下进行解释

c - 修改ELF文件

c - 虽然循环不会像 C 中预期的那样中断

c - C 中的欧拉计划 7

c - 尝试在循环中访问数组元素会导致段错误,为什么?