News for hackers. Stuff that matters.
Re:Betrayed by a bitfield (2012) by mschuster91 on Sunday July 03, 2016 @01:17PM (#12026773)
> Eh, that use of a bitfield is asking for it. What could you possibly gain from using a single bitfield in the entire struct?

A (buried way down) comment explains this:

> if you can even replace two int variables with one bitfield, you may shrink your datastructure enough to have it fit within a CPU cache line. The memory access that can then be avoided can be enough to make a noticeable difference.

https://lwn.net/Articles/479402/

Re:Betrayed by a bitfield (2012) by CamperBob2 on Sunday July 03, 2016 @06:33PM (#12027933)
if you can even replace two int variables with one bitfield, you may shrink your datastructure enough to have it fit within a CPU cache line.

But the way you should do that is by declaring an integer variable of the exact size you anticipate requiring to store your bits, and set/clear/test those bits explicitly with Boolean operators.

C bitfield semantics have always been far too hand-wavy to use for anything important. This is a perfect example (not that a separate variable will necessarily save you from a compiler stupid enough to write to adjacent structure members for no reason).

Re:Betrayed by a bitfield (2012) by mikeash on Sunday July 03, 2016 @01:19PM (#12026779)
Right, but there's only one here. Is it just an attempt to future proof in case they add a second?
Re:Betrayed by a bitfield (2012) by arcticbull on Sunday July 03, 2016 @03:02PM (#12027185)
Likely their standard practice so the addition of a second field is immaterial. Does look funky though.