Strange GCC short int conversion warning

后端 未结 6 598
南笙
南笙 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:36

    From The C Programming Language section 2.7 Type Conversion

    • If either operand is long double, convert the other to long double.
    • Otherwise, if either operand is double, convert the other to double.
    • Otherwise, if either operand is float, convert the other to float.
    • Otherwise, convert char and short to int.
    • Then, if either operand is long, convert the other to long.

提交回复
热议问题