Structure & Union
Gathering statement:
Tag {declaration definition}
Tag flag {declaration definition}
Tag flag;
mark:
Struct
union
Aggregatedeclaration:
Tag {decldefs}
Tag Identifier {Decldefs}
Tag Identifier;
TAG:
Struct
union
They are basically the same as the structure in C, except for the following exceptions:
No bit fields can explicitly specify alignment without a separate tagname space - tagname incoming the current scope is not allowed as follows: Struct ABC X;
Should be used: ABC X;
Anonymous Structure / Union can provide members of other structures / federated members to provide members with default initial values to have member functions and static member structures and combined with simple data aggregation, and are interspersed with hardware or external types. The external type can be defined by the operating system API, or is defined by the file format. Object-oriented features are provided by the class.
Static Initialization of Structure If the initial value is not provided, the static structural member will be initialized by the initial value of the member type by default. If a static initial value is provided, the member will initialize: member name, colon, expression. Members can initialize in any order. No members in the initialization list will be initialized by the default value.
Struct x {int a; int b; int C; int D = 7;
Static X x = {a: 1, b: 2}; // C is set to 0, D is 7
Static x z = {C: 4, B: 5, A: 2, D: 5}; // Z.A = 2, z.b = 5, z.c = 4, z.d = 5
The initialization of C style, depending on the order of members in the structural statement, is also supported:
Static x q = {1, 2}; // q.a = 1, q.b = 2, q.c = 0, q.d = 7
Combined static initialization needs to explicitly initialize.
Union u {Int a; double b;}
STATIC u u = {b: 5.0}; // u.b = 5.0
If the stored space occupied by the federated other members is larger, the remaining parts are initialized to zero.
Structural properties
.sizeof size in bytes
.size. Sizeof
. RALIGNOF to be aligned with the boundary value