What's the use of initializing blank bitfields

71 views Asked by At

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?

1

There are 1 answers

0
2501 On

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.