1
votes

My compiler gives me this warning: passing argument 2 of 'transform_labels' from incompatible pointer type [-Wincompatible-pointer-types] with this note: expected 'int (*)[10]' but argument is of type 'int **'

My code:

void transform_labels(int array[60000], int labels[60000][10], int NPAT){

    for(int i = 0; i < NPAT; i++){

        int aux = array[i];
        labels[i][aux] = 1;
        printf("%d\n ",*labels[i]);
        if ((i+1) % 10 == 0) putchar('>');

    }

}

int main() {

   load_mnist();
   int loop;
   int** labels;
   allocate_mem(&labels, 60000, 10);
   printf("HERE");
   transform_labels(train_label, labels, 60000);
   return 0;

}
2
This have been asked many times before. The problem is int**, which has nothing to do with arrays. Correctly allocating multi-dimensional arrays might be helpful.Lundin

2 Answers

4
votes

A pointer to a pointer cannot be converted to a pointer to an array. While an array can be converted to a pointer that only applies to the outermost dimension of a multidimensional array.

You need to change the declaration of your function:

void transform_labels(int *array, int **labels, int NPAT){
0
votes

You are allowed to pass a pointer instead of the first dimension of a function argument, and vice-versa, but all other dimensions must match. You have a second dimension [10].

You can pass it a pointer to an array of size 10, but that might just push your problem up to another point in the code, such as your allocate function. The following should compile, but it is not clear that this is what you want:

typedef int LabelSub[10];
LabelSub* labels;
allocate_mem(&labels, 60000, 10);