I have a struct that contains an unsigned char * for storing arbitrary data. At some point I want to use this data as if it were a two-dimensional array. This is how I do it:
#define DATA_SIZE 10
unsigned char *data = malloc(DATA_SIZE * DATA_SIZE * sizeof(unsigned char));
// this is not allowed
unsigned char (* matrix)[DATA_SIZE] = (unsigned char*[DATA_SIZE]) &data;
// this gives a warning and doesn't work at all
unsigned char (* matrix)[DATA_SIZE] = (unsigned char **) &data;
I want to cast a pointer to arbitrary data to a two-dimesional array, but of course I can't cast to array types. How would I need to go about this?
Thanks in advance.