Designated Initializers

When the C99 extensions setting is on, the compiler allows an extended syntax for specifying which structure or array members to initialize. Example of Designated Initializers shows an example.

Listing 1. Example of Designated Initializers
#pragma c99 on


struct X {
    int a,b,c;
} x = { .c = 3, .a = 1, 2 };

union U {
    char a;
    long b;
} u = { .b = 1234567 };

int arr1[6] = { 1,2, [4] = 3,4 };

int arr2[6] = { 1, [1 ... 4] = 3,4 }; /* GCC only, not part of C99. */