0

So I was learning about bitfields, and when I stumbled upon this link, I saw

unsigned char :0; // start a new byte

I'm wondering why that would be used, since it's wasting memory. Does it have a practical use? Where would it be used practically?

Edit: So I did read this, but is there any practical use other than cross-compiler compatibility?

Community
  • 1
  • 1
JoeyChor
  • 63
  • 1
  • 7
  • Hard to say without context, but maybe the reason was to get a specific memory layout for serialization purposes (altough this is not the only problem to overcome for good serialization...) – deviantfan Nov 24 '14 at 22:17
  • And also [this So question](http://stackoverflow.com/questions/13802728/what-is-zero-width-bit-field) – quantdev Nov 24 '14 at 22:18

1 Answers1

0

Standard actually explains this:

6.7.2.1 p12:

A bit-field declaration with no declarator, but only a colon and a width, indicates an unnamed bit-field.126) As a special case, a bit-field structure member with a width of 0 indicates that no further bit-field is to be packed into the unit in which the previous bit- field, if any, was placed.

126: An unnamed bit-field structure member is useful for padding to conform to externally imposed layouts.

2501
  • 25,460
  • 4
  • 47
  • 87