'~' operator on short/char implicitly casts to int (C / gcc)

前端 未结 1 1113
死守一世寂寞
死守一世寂寞 2021-01-25 11:31

With gcc\'s -Wconversion warning, It looks like chars and shorts are implicitly converted to ints.

#include

#pragma GCC diagnostic w         


        
相关标签:
1条回答
  • 2021-01-25 11:35

    According to the C standard (6.5.3.3), the integer promotions are performed on the operand of ~ and the result is of the promoted type. The integer promotions (6.3.1.1) basically say that all integer types smaller than int are promoted to int (if int can represent all values of the original type) or unsigned int (otherwise).

    0 讨论(0)
提交回复
热议问题