在参数传递期间我无法弄清楚这个错误。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
typedef char my_char;
void myfunc(const my_char** data)
{
printf ("%s\n", *data);
printf ("%s\n", *(data + 1));
}
int main(){
char **mydata;
mydata = malloc(sizeof(char*)*2);
mydata[0] = malloc(sizeof(char)*50);
mydata[1] = malloc(sizeof(char)*50);
memset(mydata[0],'\0',50);
memset(mydata[1],'\0',50);
strcpy (mydata[0], "Hello");
strcpy (mydata[1], "world");
myfunc((my_char**)mydata);
free (mydata[0]);
free (mydata[1]);
free (mydata);
return 0;
}
它工作正常。但是当我明确输入参数时会发出警告。为什么会这样?显示的警告是:
warning: passing argument 1 of ‘myfunc’ from incompatible pointer type
据我所知,类型转换应该有助于编译器理解指针所持有的数据类型。但在这里它根本没有帮助。