What is the purpose of the nameless bit field at the end of the structure

I am learning C. In C Primer Plus, I saw an example with a bit field as follows:

struct box_props {
    bool opaque               : 1;
    unsigned int fill_color   : 3;
    unsigned int              : 4;
    bool show_border          : 1;
    unsigned int border_color : 3;
    unsigned int border_style : 2;
    unsigned int              : 2;
};

I understand that the 4-bit unnamed bit field in the middle is used so that empty bits start with a new byte. However, I do not understand why there is another unnamed bit field at the end of the structure. What is the purpose of this? It's necessary?

+4
source share
2 answers

Is it necessary?

No, this is optional.

What is the purpose of this?

This is what the standard says in ยง9.6.2, C ++ 11 (draft N3337, my hit):

, , . - . [: , . - ]. . - .

, , struct 2- , , , struct 2-. , , . , ยง9.6.1:

-. - . . - .

, , struct/class -.

+5

? ?

. , .

.

+5

All Articles