So I am passing a 3 by 3 array of float points. The function foo will allocate memory for each pointer. Here is the code.
#include <stdio.h>
#include <stdlib.h>
void foo(float ***A);
int main(int argc, char **argv) {
float* A[3][3];
foo(&A);
}
void foo(float ***A) {
int i,j;
for(i=0;i<3;i++){
for(j=0;j<3;j++){
A[i][j] = malloc(2*sizeof(float));
A[i][j][0] = 21;
}
}
}
Why does this does not work? It throws the following error:
C:\Users\tony\Code\MPI>gcc test.c
test.c: In function 'main':
test.c:8: warning: passing argument 1 of 'foo' from incompatible pointer type
test.c:4: note: expected 'float ***' but argument is of type 'float *** (*)[3][3]'
So If I call foo(A) instead of foo(&A) I get this error instead:
C:\Users\tony\Code\MPI>gcc test.c
test.c: In function 'main':
test.c:8: warning: passing argument 1 of 'foo' from incompatible pointer type
test.c:4: note: expected 'float ***' but argument is of type 'float * (*)[3]'
typeofshould besizeof