运算符优先级问题

1、gDCBus_Voltage = ( (pCommBuffer->ReceiveBuffer[3] << 8) + pCommBuffer->ReceiveBuffer[2])*f32Coeff;

2、gDCBus_Voltage = ( pCommBuffer->ReceiveBuffer[3] << 8 + pCommBuffer->ReceiveBuffer[2])*f32Coeff;

 

写法1是正确的

写法2是不对的,因为移位运算符的优先级比 +这个运算符的优先级低。

 

posted @ 2022-02-10 21:02  艾诺洛格_泡尔斯伊  阅读(31)  评论(0编辑  收藏  举报