News for hackers. Stuff that matters.
Re:A Better Way to Implement Bit Fields by loeg on Wednesday November 14, 2018 @06:10PM (#18455101)
Hm. I like the approach except for the overloaded meaning of packed. In C, packing means byte-aligned packing, rather than bit-packing. These seem like separate concepts. (Both are useful! I just think bit-packing should get its own special name.)
Re:A Better Way to Implement Bit Fields by vvanders on Wednesday November 14, 2018 @06:22PM (#18455220)
Yeah, packing is a pretty well defined to mean adding additional empty bits to keep fields word-aligned.
Re:A Better Way to Implement Bit Fields by platinumrad on Wednesday November 14, 2018 @07:15PM (#18455631)
In my experience that's referred to as padding, not packing. A packed struct is what you get when you remove all of the padding. Packing is therefore removing padding, not adding it.
Re:A Better Way to Implement Bit Fields by iainmerrick on Wednesday November 14, 2018 @06:35PM (#18455326)
Word-aligned? No, that's the opposite of packing!

I'd say "packing" is ambiguous and could refer to either bit-aligned or byte-aligned data. But if your fields are less than 8 bits wide, I would assume "packing" means bit-packing.

Re:A Better Way to Implement Bit Fields by loeg on Wednesday November 14, 2018 @07:33PM (#18455736)
E.g., if your packed struct is { bool a; uint32_t b; }, you probably don't want a totally misaligned-by-one-bit 'b'.
Re:A Better Way to Implement Bit Fields by loeg on Wednesday November 14, 2018 @07:32PM (#18455730)
Byte-aligned, in C.