views:

31

answers:

1

In C99 (and not in C++), it's possible to initialize structs using this syntax:

struct info
{
    char    name[8+1];
    int     sz;
    int     typ;
};

struct info  arr[] =
{
    [0] = { .sz = 20, .name = "abc" },
    [9] = { .sz = -1, .name = "" }
};

What happens to the unspecified fields?

+7  A: 
KennyTM
Exactly what I wanted to know, complete with standard quote. Thanks!
Matt Joiner
@Matt Joiner: Was there ever any doubt? Oh, and for completeness see §6.7.8 (Initialization)/10, which effectively states that such static storage is NULL/0 initialized.
torak
Thank you torak.
Matt Joiner
A useful consequence of this fact is that `{ 0 }` is a universal zero-initializer which can be used for any aggregate type (and actually any type at all, IIRC, though some compilers might give warnings if it's used for simple types).
R..