When is it worthwhile to use bit fields?

前端 未结 11 607
伪装坚强ぢ
伪装坚强ぢ 2020-12-01 09:10

Is it worthwhile using C\'s bit-field implementation? If so, when is it ever used?

I was looking through some emulator code and it looks like the registers for the c

11条回答
  •  一个人的身影
    2020-12-01 09:21

    Bit fields were used in the olden days to save program memory.

    They degrade performance because registers can not work with them so they have to be converted to integers to do anything with them. They tend to lead to more complex code that is unportable and harder to understand (since you have to mask and unmask things all the time to actually use the values.)

    Check out the source for http://www.nethack.org/ to see pre ansi c in all its bitfield glory!

提交回复
热议问题