6.57 Initialization
...
If there are fewer initializers in a brace-enclosed list than there are members of an aggregate, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.
那么objects that have static storage duration是如何进行初始化呢,有明确规定:
If an object that has static storage duration is not initialized explicitly. it is
initialized implicitly as if every member that has arithmetic type were assigned 0 and every member that has pointer type were assigned a null pointer constant.
对于数值类型就用0初始化,对于指针用空指针常量。而C99也有类似的内容:
6.7.8 Initialization
......
If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.
.....
If an object that has static storage duration is not initialized explicitly,
then:
— if it has pointer type, it is initialized to a null pointer;
— if it has arithmetic type, it is initialized to (positive or unsigned) zero;
— if it is an aggregate, every member is initialized (recursively) according to these rules;
— if it is a union, the first named member is initialized (recursively) according to these rules.
C++则是这样规定的:
8.5 Initializers
8.5.1 Aggregates
If there are fewer initializers in the list than there are members in the aggregate, then each member not explicitly initialized shall be value-initialized (8.5). [Example:
struct S { int a; char* b; int c; };
S ss = { 1, "asdf" };
initializes ss.a with 1, ss.b with "asdf", and ss.c with the value of an expression of the form int(), that is, 0. ]
那个回答之所以是错的,是以为它遵循If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate.这条规定,实则不是,对于初始化器不足聚集元素数量的初始化是另有规定的。