5.67 Designated initializers in C99

In C90, there is no way to initialize specific members of arrays, structures, or unions. C99 supports the initialization of specific members of an array, structure, or union by either name or subscript through the use of designated initializers.

For example:

typedef struct
    char *name;
    int rank;
} data;
data vars[10] = { [0].name = "foo", [0].rank = 1,
                  [1].name = "bar", [1].rank = 2,
                  [2].name = "baz", 
                  [3].name = "gazonk" };

Members of an aggregate that are not explicitly initialized are initialized to zero by default.

Related concepts
5.63 New language features of C99
5.65 // comments in C99 and C90
5.66 Compound literals in C99
5.68 Hexadecimal floating-point numbers in C99
5.69 Flexible array members in C99
5.70 __func__ predefined identifier in C99
5.71 inline functions in C99
5.72 long long data type in C99 and C90
5.73 Macros with a variable number of arguments in C99
5.74 Mixed declarations and statements in C99
5.75 New block scopes for selection and iteration statements in C99
5.76 _Pragma preprocessing operator in C99
5.77 Restricted pointers in C99
5.79 Complex numbers in C99
Non-ConfidentialPDF file icon PDF versionARM DUI0472J
Copyright © 2010-2013 ARM. All rights reserved.