I have a structure, say foo that looks like this,
struct foo {
size_t n;
size_t **point;
};
There are other members in the structure they are not important to the question. Now, I want to static initialize the structure.
int main(void)
{
struct foo *bar = &(struct foo){
.n=4,
/* ERROR HERE */ .point=(size_t[][n]){ {1, 2, 3, 4}, {5, 6, 7, 8}}
};
return 0;
}
There are two problem in the line indicated. First, understandably the compiler doesn't recognise n and is there any way I can do something similar without creating a variable before? Secondly, and most importantly, I realized that I have no idea how to create a 2D array and assign it to a pointer to pointers statically. Please help. I tried the following variations but nothing worked.
/* Variation 1 */ .point=(size_t[][4]){ {1, 2, 3, 4}, {5, 6, 7, 8}}
/* Variation 2 */ .point=(size_t**)(size_t[][4]){ {1, 2, 3, 4}, {5, 6, 7, 8}}
/* Variation 3 */ .point=&(size_t[][4]){ {1, 2, 3, 4}, {5, 6, 7, 8}}
foocreated from it does not.