简体   繁体   English

警告:从不兼容的指针类型 [-Wincompatible-pointer-types]| 传递 'transform_labels' 的参数 2 |

[英]Warning: passing argument 2 of 'transform_labels' from incompatible pointer type [-Wincompatible-pointer-types]|

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 **'我的编译器给了我这个警告:从不兼容的指针类型 [-Wincompatible-pointer-types] 中传递 'transform_labels' 的参数 2 并带有此注释:预期为 'int (*)[10]' 但参数的类型为 '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;

}

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){

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].你有第二个维度 [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.您可以将一个指向大小为 10 的数组的指针传递给它,但这可能只会将您的问题推到代码中的另一点,例如您的分配函数。 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);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 警告:从不兼容的指针类型 [-Wincompatible-pointer-types] 传递“接受”的参数 2 - warning: passing argument 2 of ‘accept’ from incompatible pointer type [-Wincompatible-pointer-types] 从不兼容的指针类型 [-Wincompatible-pointer-types] 获取传递“pthread_create”参数 3 的警告 - Getting warning of passing argument 3 of ‘pthread_create’ from incompatible pointer type [-Wincompatible-pointer-types] 警告:从不兼容的指针类型 [-Wincompatible-pointer-types] 传递 'display' 的参数 1 - warning: passing argument 1 of 'display' from incompatible pointer type [-Wincompatible-pointer-types] 警告:从不兼容的指针类型返回 [-Wincompatible-pointer-types]| - warning: return from incompatible pointer type [-Wincompatible-pointer-types]| 从不兼容的指针类型 [-Wincompatible-pointer-types] 传递“send_to_host”的参数 2 - passing argument 2 of ‘send_to_host’ from incompatible pointer type [-Wincompatible-pointer-types] 错误:- 从不兼容的指针类型 [-Wincompatible-pointer-types] 传递“get_string”的参数 1 - ERROR :- passing argument 1 of 'get_string' from incompatible pointer type [-Wincompatible-pointer-types] 来自不兼容指针类型的赋值[Wincompatible-pointer-types] - Assignment from incompatible pointer type[Wincompatible-pointer-types] 来自不兼容的指针类型[-Wincompatible-pointer-types]的赋值 - assignment from incompatible pointer type [-Wincompatible-pointer-types] RecursiveFree函数-警告:从不兼容的指针类型[-Wincompatible-pointer-types]进行初始化 - RecursiveFree Function - Warning: initialization from incompatible pointer type [-Wincompatible-pointer-types] C中的函数指针:警告:来自不兼容指针类型[-Wincompatible-pointer-types]的赋值 - Function pointers in C: warning: assignment from incompatible pointer type [-Wincompatible-pointer-types]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM