A tool I use produces the following output:
#define VAR { {1, {2,3}}, {2, {5,1,2,3,4}}, {1, {1}} }
I want to use this in my program. The question is how to use it properly.
My first approach was something like this:
#define VAR { {1, {2,3}}, {2, {5,1,2,3,4}}, {1, {1}} }
#include <stdio.h>
typedef struct vars {
int first;
int second[];
} vars;
int main( int argc, char** argv ) {
vars allvars[] = VAR;
printf("%i\n",allvars[0].second[0]);
return 0;
}
But gcc doesn't like it:
error: initialization of flexible array member in a nested context
My second approach was about a 3d-array:
#define VAR { {1, {2,3}}, {2, {5,1,2,3,4}}, {1, {1}} }
#include <stdio.h>
int main( int argc, char** argv ) {
int allvars[3][2][2] = VAR;
printf("%i\n",allvars[1][1][3]);
return 0;
}
Similar reaction of the compiler:
warning: braces around scalar initializer
Does anyone know how to deal with it? Is it even possible to use an initialiser list such as the given one or do anybody knows a nice hack to deal with this problem?