I have a set of structs, defined as follows:
typedef struct
{
int index;
int array[10];
}
Item;
typedef struct
{
Item A;
Item B;
Item C;
}
Collection;
And I want to declare a variable of type Collection as follows:
Collection collection =
{
{ 1, 0 }, /* item A */
{ 2, 0 }, /* item B */
{ 3, 0 } /* item C */
};
Will this set the three index variables to 1, 2, and 3, while at the same time initializing all three array[] variables with zero?
It appears to be working on my compiler, but I would like to know if this is the standard behaviour.
This is standards compliant. See the section — 6.7.8 Initialization. Further, you can use designated initializers in C99 conforming compilers.