In life, I cannot understand the correct syntax for creating an array of structures in C. I have tried this:
struct foo { int x; int y; } foo[][] = { { { 1, 2 }, { 4, 5 }, { -1, -1 } }, { { 55, 44 } { 100, 200 }, } };
So, for example, foo [1] [0] .x == 100, foo [0] [1] .y == 5, etc. But GCC spits out a lot of mistakes.
If someone can provide the correct syntax, that will be great.
EDIT: Ok, I tried this:
struct foo { const char *x; int y; }; struct foo bar[2][] = { { { "A", 1 }, { "B", 2 }, { NULL, -1 }, }, { { "AA", 11 }, { "BB", 22 }, { NULL, -1 }, }, { { "ZZ", 11 }, { "YY", 22 }, { NULL, -1 }, }, { { "XX", 11 }, { "UU", 22 }, { NULL, -1 }, }, };
But GCC gives me “the elements of the bar array are of an incomplete type” and “the extra elements in the array initializer”.