const int status[STATUS_SIZE] = {
[0] = -1,
[1] = 0,
[2] = 1,
};
and
const char *messages[MESSAGE_SIZE] = {
[0] = "OK",
[1] = "NG",
};
Can you explain?
C99 introduces Designated Initializers, with which you can initialize an array in any order by using the index.
Standard C90 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 C90 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 };