by matthavener · 11y ago · 0 comments
const char *lookup[] = {
[0] = "ZERO",
[1] = "ONE",
[4] = "FOUR"
};
assert(strcmp(lookup[0], "ZERO") == 0);
(not available in C++ or pre-C99) enum fields = { x, y, z };
int point[] = {
[x] = 1,
[y] = 2,
[z] = 3
};
This is used pretty extensively in the QEMU codebase, which is where I first learned it.