传递给函数时,C类型从char*转换为int
我试图将文件名传递给线程函数,但它的类型在函数内部转换为int传递给函数时,C类型从char*转换为int,c,C,我试图将文件名传递给线程函数,但它的类型在函数内部转换为int struct Data { char file_name; } void *Requestor(void *args) { struct Data *data = (struct Data*)args; printf("%s\n", data->file_name); //says expected char* but argument is type of int } int file_count
struct Data {
char file_name;
}
void *Requestor(void *args) {
struct Data *data = (struct Data*)args;
printf("%s\n", data->file_name); //says expected char* but argument is type of int
}
int file_count = 5;
struct Data files[file_count];
for (int i = 0; i < file_count; i++) {
printf("%s\n", argv[5 + i]); //this prints the file_name correctly;
files[i].file_name = argv[5 + i]; // I get: warning: assignment makes integer from pointer without a cast [-Wint-conversion when compiling
int thread = pthread_create(&(requesterThreads[i]), NULL, Requestor, &files[i]);
}
struct数据{
字符文件名;
}
void*请求者(void*args){
结构数据*数据=(结构数据*)参数;
printf(“%s\n”,data->file_name);//表示预期的字符*,但参数的类型为int
}
int file_count=5;
结构数据文件[文件计数];
对于(int i=0;i
您缺少一个*
:字符文件名;
应该是char*文件名;
编译器警告您它是int
而不是char
的原因是char
在varargs中使用时被隐式提升为int
。您缺少了*
:charile_name;
应该是char*file_name;
编译器警告您它是int
而不是char
的原因是char
在varargs中使用时隐式提升为int