Reputation: 618
I'm trying to pass a file name to a threaded function but it's type is converted to int inside the function
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]);
}
Upvotes: 0
Views: 65
Reputation: 4241
You're missing a *
: char file_name;
should be char *file_name;
The reason the compiler warns you that it's an int
instead of a char
is that char
is implicitly promoted to int
when used in varargs.
Upvotes: 4