Why are integer types promoted during addition in C?

前端 未结 4 1351
礼貌的吻别
礼貌的吻别 2020-12-06 09:45

So we had a field issue, and after days of debugging, narrowed down the problem to this particular bit of code, where the processing in a while loop wasn\'t happening :

4条回答
  •  醉梦人生
    2020-12-06 10:02

    Literal 1 in of int, i.e. in your case int32 type, so operations with int32 and int16 give results of int32.

    To have result of numberA + 1 statement as uint16_t try explicit type cast for 1, e.g.: numberA + (uint16_t)1

提交回复
热议问题