0

Is there any difference in:

char *foo[size];

and

char (*foo)[size];

In this example, the compiler complains if I declare my pointer with the first method:

void alloc_unitary_matrix(size_t size, char (*matrix)[size]) {
    matrix = malloc(size*size);
    memset(matrix, 1, size*size);
}

void main() {
   size_t size = 10;
   char (*matrix)[size];
   alloc_unitary_matrix(size,matrix);
}

What did I misunderstand?

nowox
  • 25,978
  • 39
  • 143
  • 293
  • Better declare as a `char **foo`. But you'll need to pass multiple size variables to functions. – m0nhawk May 30 '15 at 15:17
  • It seems to me that this is a parsing issue rather than compilation, and if you remove `size` from the arguments declaration (which makes no sense anyway), using `char *matrix[]` or `char **matrix` is equivalent. – Gerard van Helden May 30 '15 at 15:19

0 Answers0