小编Rav*_*avi的帖子

C程序中的整数推广

我写了一个简单的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)

c integer-promotion

5
推荐指数
1
解决办法
456
查看次数

标签 统计

c ×1

integer-promotion ×1