Strange GCC short int conversion warning

后端 未结 6 614
南笙
南笙 2021-01-18 15:41

I have a bit of C code, which goes exactly like this:

short int fun16(void){
    short int a = 2;
    short int b = 2;
    return a+b;
}

Wh

6条回答
  •  醉酒成梦
    2021-01-18 16:43

    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.

    Refer the following post: Why must a short be converted to an int before arithmetic operations in C and C++?

提交回复
热议问题