3 ms·
Largely academic? That is just not true in any sense. Bitfields are extremely important in many cases, not the least of which is making lock free data structur
by BubRoss 7y ago
Largely academic? That is just not true in any sense. Bitfields are extremely important in many cases, not the least of which is making lock free data structures where you need to pack in information that can be atomically swapped.
- mytailorisrich 7y agoI have been developing professionally in C on embedded systems for 20 years and never had to interact with the 'bitfield' C feature. In fact, many internal coding standards forbid its use because it is poorly defined and compiler-dependent. Moreover, it does not guarantee atomicity so if atomicity is critical then you want to access the actual bitfield 'manually'.
- BubRoss 7y agoWhen dealing with lock free algorithms the amount of bits that you can do a compare and swap on are limited. For x64 it is 64 bits unaligned or 128 bits aligned. Needing to use all of these bits as efficiency as possible is common and bitfields are a big part of this. Whether you use bitfields frequently in your work is irrelevant.
- mytailorisrich 7y agoI think you're still missing the point that we're specifically discussing the 'bit field' C language feature, not bit fields in general. I do use bit fields, everyone does at one point or another when working on embedded systems. But commonly this is done 'manually' (with masks and shifts) without using C's support for bit fields.
- BubRoss 7y agoI would rather let the compiler do that. If that's what you were talking about, why did you say 'bitfields aren't atomic' ?