- 论坛徽章:
- 1
|
gcc --std=c89 是可以通过的 但这个功能好像真是c99才引进的
下面引自 c - in a nushell
8.3.2. Initializing Specific Elements
C99 has introduced element designators to allow you to associate initializers with specific elements . To specify a certain element to initialize, place its index in square brackets. In other words, the general form of an element designator for array elements is:
[constant_expression]
The index must be an integer constant expression. In the following example, the element designator is [A_SIZE/2]:
#define A_SIZE 20
int a[A_SIZE] = { 1, 2, [A_SIZE/2] = 1, 2 };
This array definition initializes the elements a[0] and a[10] with the value 1, and the elements a[1] and a[11] with the value 2. All other elements of the array will be given the initial value 0. As this example illustrates, initializers without an element designator are associated with the element following the last one initialized.
If you define an array without specifying its length, the index in an element designator can have any non-negative integer value. As a result, the following definition creates an array of 1,001 elements:
int a[ ] = { [1000] = -1 }; |
|