我写了一个简单的C程序,想知道整数提升是否正在发生.
请解释整数推广如何发生以及如何避免?
/* start of main */
unsigned short int res;
unsigned short int bsp;
signed short int analog;
bsp = 2215;
analog = 2213;
if((signed short int)(bsp - analog) > 0){
res = bsp - analog;
printf("%d", res);
}
else{
res = analog - bsp;
printf("%d", res);
}
Run Code Online (Sandbox Code Playgroud)