I get segmentation fault when running this but no errors. I am trying to pass pointer to an array of pointers, initialize it as an array of pointers, fill the array and the data available to the calling function.
static void test4(int ***arr)
{
int *values = (int *) MEM_mallocN(sizeof(int) * 3, "*values");
values[0] = 0;
values[1] = 1;
values[2] = 2;
*arr = (int **) MEM_mallocN(sizeof(int *) * 3, "*arr");
*arr[0] = &values[0];
*arr[1] = &values[1];
*arr[2] = &values[2]; /* this line causes crash */
}
static void test3(void)
{
int **arr = NULL;
test4(&arr);
for (int i = 0; i < 3; i++) {
printf("arr[%d] = %p \n", i, arr[i]);
}
for (int i = 0; i < 3; i++) {
printf("arr[%d] = %d \n", i, *arr[i]);
}
}