Is there any way to malloc a large array, but refer to it with 2D syntax? I want something like:
int *memory = (int *)malloc(sizeof(int)*400*200);
int MAGICV
In the same vein as Cogwheel's answer, here's a (somewhat dirty) trick that makes only one call to malloc():
#define ROWS 400
#define COLS 200
int** array = malloc(ROWS * sizeof(int*) + ROWS * COLS * sizeof(int));
int i;
for (i = 0; i < ROWS; ++i)
array[i] = (int*)(array + ROWS) + (i * COLS);
This fills the first part of the buffer with pointers to each row in the immediately following, contiguous array data.