I have an array of array with negative index. It is an array which has real dimensions [dim_y + 40][dim_x + 40] but the user uses the array like it has dimensions [dim_y][dim_x].
So i see the array's rows lets say from -20 to dim_y + 20 but a user sees only from 0 to dim_y.
First i had global and already defined the dimensions dim_x, dim_y, so i had this:
Code:
int map_boundaries[dim_y + 40][dim_x + 40];
int (*map)[dim_x+40] = (int(*)[dim_x+40])&map_boundaries[20][20];
In fact, 'map' points to 'map_boundaries' , map[0][0] is map_boundaries[20][20].
I did what is posted in the second post here:
Negative array indexing - Everything2.com
I want 'map' to be global. Until now i had defined the dim_y and dim_x so that worked fine.
Now i just need to read from a user the dim_x and dim_y.
Until now i have global
Code:
int **map_boundaries;
and then in main i use calloc:
Code:
map_boundaries = (int **)calloc(dim_y + 40,sizeof(int*));
for(i = 0; i < dim_y + 40; i++){
map_boundaries[i] = (int *)calloc(dim_x + 40,sizeof(int));
}
but i dont know how to declare this line now:
Code:
int (*map)[dim_x+40] = (int(*)[dim_x+40])&map_boundaries[20][20];