I declared many pointers to variable length array (VLA) in a function to allocate 2-D arrays dynamically; for example,
int M, N; // have some value
double (*arr1)[N] = calloc(M, sizeof(double [N]));
double (*arr2)[N] = calloc(M, sizeof(double [N]));
double (*arr3)[N] = calloc(M, sizeof(double [N]));
... // so many declarations
Because the function became very long, I tried to split it into several functions, each of which requires all that pointers as the argument. Instead of passing many things in the function (which is bad for a performance), I declared a struct containing all pointers globally to reduce the number of argument:
struct ptrpack {
int M, N;
double (*arr1)[N];
double (*arr2)[N];
...
};
// then each function just takes a single struct rather than many pointers
void foo(struct ptrpack p) {
...
}
However, a pointer to VLA is not allowed in struct. GCC extension allows it if the struct definition is in a function, but the definition is in global scope in my case.
What is the best solution for this problem? I strongly prefer to use a pointer to VLA, not an ordinary pointer.