0

I have a matrix created with size based on a variable. I cannot seem to pass this matrix for a function i created.

Num and rank is recieved via OpenMPI.

The error i get is something like 'expected ‘int **’ but argument is of type ‘int (*)[(sizetype)(num)]’'

Here is what I have:

int gHolder(int** spanningTree, int size, int id, int token){
  if( size == 0 ) return -1;
  if( id < 0 || id >= size || token < 0 || token >= 0) return -1; 
  if(token == id) return id;

  int j;
  int holder;
  for(j = 0; j<size; j++){
    if(spanningTree[id][j] == 1){
      holder = gHolder(spanningTree, size, j, token);
      if(holder != -1) return j;
    }
  }
  return -1;
}

int main(int argc, char * argv[]) {
    int rank;
    int num;
    MPI_Init(&argc, &argv);
    MPI_Comm_size(MPI_COMM_WORLD, &num);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);

    int mat[num][num];
    int tokenHolder = 7;
    mat[0][1] = 1;
    mat[0][2] = 1;
    mat[1][0] = 1;
    mat[2][0] = 1;
    mat[2][3] = 1;
    mat[2][4] = 1;
    mat[3][2] = 1;
    mat[4][2] = 1;
    mat[4][5] = 1;
    mat[4][6] = 1;
    mat[5][4] = 1;
    mat[6][4] = 1;
    mat[6][7] = 1;
    mat[6][8] = 1;
    mat[7][6] = 1;
    mat[8][6] = 1;
    holder = gHolder(mat, num, rank, tokenHolder); 
smith
  • 194
  • 3
  • 15
  • 2
    http://stackoverflow.com/questions/20297594/warning-expected-int-but-argument-is-of-type-int-sizetypen - The question from this link is already a duplicate, but has answers for exactly the same issue – nnn Nov 22 '15 at 00:02
  • [This](http://stackoverflow.com/a/3912959/2304215) should be very helpful. – chrk Nov 22 '15 at 00:05
  • 1) There is no matrix/2D array in the function, but a pointer to pointer. 2) C does not support _methods_, but only _functions_. – too honest for this site Nov 22 '15 at 01:25

1 Answers1

0

You declared spanningTree improperly. You need to change the argument order, then you can declare it as either:

int gHolder(int size, int spanningTree[size][size], int id, int token)

or:

int gHolder(int size, int (*spanningTree)[size], int id, int token)

The size declaration needs to precede the reference.

Tom Karzes
  • 22,815
  • 2
  • 22
  • 41