What is the meaning of standalone square brackets inside of a C array of a custom type?
typedef enum {
BAR_1 = 0,
BAR_2,
BAR_3,
} bar_types;
typedef struct {
int is_interesting;
int age;
} foo_s;
static foo_s bars[] = {
[BAR_1] = {1, 2}, /* What is being done here? */
[BAR_2] = {1, 41},
[BAR_3] = {0, 33},
};
In the above code, what is the meaning of [BAR_1] = {1, 2}
? When is it possible to use standalone square brackets?
I've noticed that if I add duplicate value in brackets, clang gives an warning about subobject initialisation.
static foo_s bars[] = {
[BAR_1] = {1, 2},
[BAR_2] = {1, 41},
[BAR_3] = {0, 33},
[BAR_3] = {0, 33},
};
-----
$clang example.c
example.c:17:19: warning: subobject initialization
overrides initialization of other fields within its
enclosing subobject [-Winitializer-overrides]
[BAR_3] = {0, 33},
^~~~~~~
What is a C subobject?