I am puzzled by the memory allocation and accesses to a matrix of pointers in an application I am working in.
There is a matrix defined as:
typedef double (*foo)[n/m][m][m];
Which I understand to be a three-dimensional matrix storing pointers to doubles. The memory allocation for all dimensions is done automatically.
Nonetheless, the following appears:
foo bar = (foo) malloc(sizeof(double) * n * n);
What exactly is this cast doing?. Furthermore, why do we need to allocate memory for these doubles?. I would think the matrix only contains pointers, which would later be initialized with the memory addresses of doubles declared separately.
Finally, I am, also confused by the way this matrix is accessed during its initialization:
bar[i/m][j/m][i%m][j%m] = value;
Where i and j are smaller than N. Mainly, I would like to know what the fourth index is adressing.
Thank you so much in advance for your help!