私はシンプルな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);
}
ヒント: 'printf("%d "、res);'見て... –
@Ravi整数昇格については、Souravが言ったことを参照してください。あなたは "普通の算術変換"を意味しますか? –
'bsp-analog'と' analog-bsp'の両方がプロモーションを引き起こします。 – Sergio