매개 변수 전달 중에이 오류를 알아낼 수 없습니다.C에서 이중 포인터를 형변환
#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
는 지금까지 내가 아는 한, 타입 캐스팅은 컴파일러가 포인터에 들고되는 데이터의 유형, 이해하는 데 도움이됩니다. 그러나 여기에서는 전혀 도움이되지 않습니다.
'const my_char **'와'my_char **'는 호환되지 않습니다. –
이것은 downvotes에 대한 확실하지 않은 합리적인 질문입니다. 그것은 [C FAQ] (http://c-faq.com/ansi/constmismatch.html)에 있지만 다른 소개 자료는 주제를 다루지 않았을 수 있습니다. –
@SouravGhosh 나는 const가별로 차이가 없다고 생각했다. – 0aslam0