- 论坛徽章:
- 0
|
不必客气,我查了手册,这个写法是 C99 支持的。gcc 的手册说:
5.21 Designated Initializers
Standard C89 requires the elements of an initializer to appear in a fixed order, the same as the order of the elements in the array or structure being initialized.
In ISO C99 you can give the elements in any order, specifying the array indices or structure field names they apply to, and GNU C allows this as an extension in C89 mode as well. This extension is not implemented in GNU C++.
To specify an array index, write `[index] =' before the element value. For example,
int a[6] = { [4] = 29, [2] = 15 };
is equivalent to
int a[6] = { 0, 0, 15, 0, 29, 0 };
The index values must be constant expressions, even if the array being initialized is automatic.
......
我测试了一下,结果跟上面所说是一致的,即未指定的分量值为 0. |
|