When is it worthwhile to use bit fields?

前端 未结 11 604
伪装坚强ぢ
伪装坚强ぢ 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:47

    In the 70s I used bit fields to control hardware on a trs80. The display/keyboard/cassette/disks were all memory mapped devices. Individual bits controlled various things.

    1. A bit controlled 32 column vs 64 column display.
    2. Bit 0 in that same memory cell was the cassette serial data in/out.

    As I recall, the disk drive control had a number of them. There were 4 bytes in total. I think there was a 2 bit drive select. But it was a long time ago. It was kind of impressive back then in that there were at least two different c compilers for the plantform.

    The other observation is that bit fields really are platform specific. There is no expectation that a program with bit fields should port to another platform.

提交回复
热议问题