c - integer downcast

后端 未结 3 2090
有刺的猬
有刺的猬 2020-12-31 15:45

About integer numbers downcasts in C, e.g.

An int value 000F\'E000 downcast to short or unsigned short will become E000.
shor

3条回答
  •  误落风尘
    2020-12-31 16:16

    Downcast cuts the bits, up-cast depends on "signedness". Up-cast on unsigned types adds zero bits to the value, up-cast on signed types replicates the sign bit. In this way, the expression has the same value before and after an upcast.

提交回复
热议问题