Designated initializers

Changes in new versions / C99

struct Window {
    int x;
    int y;
    int width;
    int height;
};

// *** before: ***
/* C89: the values follow the order of the fields, so which number
   is which has to be looked up, and no field can be skipped */
struct Window bigOld = {0, 0, 800, 600};
int limitsOld[5] = {0, 0, 10, 0, 20};
/* bigOld.width is 800 */

printf("bigOld.width is %d\n", bigOld.width);

// *** in version C99: ***
//each value names its field, and the fields left out are zero
struct Window big = {.width = 800, .height = 600};
struct Window tall = {.height = 900, .width = 300};  //any order in C
int limits[5] = {[2] = 10, [4] = 20};                //arrays by index
//big.width is 800
//big.x is 0
//tall.height is 900
//limits[4] is 20

printf("big.width is %d\n", big.width);
printf("big.x is %d\n", big.x);
printf("tall.height is %d\n", tall.height);
printf("limits[4] is %d\n", limits[4]);