What is the meaning of double curly braces initializing a C-struct?

It initialises all fields of the POD structure to 0.

Rationale:

const SomeStruct init = {Value};

Initialises the first field of SomeStruct to Value, the rest of the structure to zero (I forget the section in the standard, but it’s there somewhere)

Thus:

const SomeOtherStruct init = {{Value}};

Initialises the first field of the first field of the structure (where the first field of the structure is itself a POD struct) to Value, and the rest of the first field to zero, and the rest of the structure to 0.

Additionally, this only isn’t working because c++ forbids implicit conversion of int to enum types, so you could do:

const SomeOtherStruct init = {{TEnum(0)}};

Leave a Comment