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
Quoting the standard (§6.3.1.1 ¶2):
The following may be used in an expression wherever an
int
orunsigned int
may be used:
- An object or expression with an integer type (other than
int
orunsigned int
) whose integer conversion rank is less than or equal to the rank ofint
andunsigned int
.- A bit-field of type
_Bool
,int
,signed int
, orunsigned int
.If an
int
can represent all values of the original type, the value is converted to anint
; otherwise, it is converted to anunsigned int
. These are called the integer promotions. All other types are unchanged by the integer promotions.
The -Wconversion flag warns about:
Warn for implicit conversions that may alter a value. This includes conversions between real and integer, like
abs (x)
whenx
isdouble
; conversions between signed and unsigned, likeunsigned ui = -1;
and conversions to smaller types, likesqrtf (M_PI)
. Do not warn for explicit casts likeabs ((int) x)
andui = (unsigned) -1
, or if the value is not changed by the conversion like inabs (2.0)
. Warnings about conversions between signed and unsigned integers can be disabled by using-Wno-sign-conversion
.