Does bit shift automatically promote chars to int? [duplicate]

穿精又带淫゛_ 提交于 2019-12-01 21:39:49

The result type is int in normal C implementations.1

Per C 2011 (N1570) 6.5.7, “The integer promotions are performed on each of the operands. The type of the result is the that of the promoted left operand.”

Per 6.3.1.1 2, the integer promotions are, for objects or expressions of integer type with rank less than or equal to the rank of int and unsigned int: “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.”


1There has been discussion elsewhere in Stack Overflow from which it seems that a bizarre C implementation could have a char of the same width as int, which leads to some unusual behavior.

C11 Standard, section 6.5.7 Bitwise shift operators, states:

The integer promotions are performed on each of the operands. The type of the result is that of the promoted left operand.

This means that the values are converted to int and then the operation is performed; the result of your expression is int.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!