Overflow in bit fields

后端 未结 4 967
野趣味
野趣味 2021-02-13 04:48

can I trust that the C compiler does modulo 2^n each time I access a bit field? Or is there any compiler/optimisation where a code like the one below would not print out Overflo

4条回答
  •  情书的邮戳
    2021-02-13 05:24

    No. The compiler allocates 2 bits to the field, and incrementing 3 results in 100b, which when placed in two bits results in 0.

提交回复
热议问题