I have 3 integers A
, B
& C
from which I make pointers that I group in an array arrayABC
of pointers to pointers:
int A = 1;
int B = 2;
int C = 3;
int *ptA = &A;
int *ptB = &B;
int *ptC = &C;
int **arrayABC[] = { &ptA, &ptB, &ptC };
Meanwhile I have the array of integers DEF
:
int DEF[] = {4,5,6};
I would like to wrap it in an array arrayDEF
of pointers to pointers offering the same interface as the array arrayABC
. I tried the following:
int **arrayDEF[] = &(int *){&DEF};
My final goal is to be able to group arrayABC
and arrayDEF
in a parent array arrayGlobal
like that:
int ***arrayGlobal[] = {arrayABC,arrayDEF};
I need to be able to access arrayGlobal
like that:
printf("A = %dn", ***arrayGlobal[0][0]); // A = 1
printf("B = %dn", ***arrayGlobal[0][1]); // B = 2
printf("C = %dn", ***arrayGlobal[0][2]); // C = 3
printf("D = %dn", ***arrayGlobal[1][0]); // D = 4
printf("E = %dn", ***arrayGlobal[1][1]); // E = 5
printf("F = %dn", ***arrayGlobal[1][2]); // F = 6
I’m able to compile without any error. However, the execution leads to a segmentation fault. I suspect that the type of arrayDEF
(pointer to pointer to table of integers) is similar to the one of arrayABC
(table of pointers to pointers to integers) but not equivalent. Do you confirm ?
I can’t change the structure of arrayABC
(imposed by an external file) but I can adapt arrayDEF
. Would there be a way to make arrayDEF
a table of pointers to pointers to each item of DEF
?