#define MATRIX_ALLOC(t, x, y) (t(*)[y])malloc(sizeof(t) * x * y)

char (p*)[3] = MATRIX_ALLOC(char, 5, 3);
...
free(p);