pthread_create with no arguments?
13,364
Your function has to match the pthread one. Meaning it needs to take and return a void*
. Use void* showart(void*);
instead.
Author by
Johnny Johnson
Updated on June 28, 2022Comments
-
Johnny Johnson almost 2 years
I want to create a thread with no function arguments but I keep getting errors that are seriously bugging me because I cant get something super simple to work right
Heres my code:
#include<stdio.h> #include<array> #include<pthread.h> #include<fstream> #include<string> void *showart(NULL); int main(int argc, char** argv){ pthread_t thread1; pthread_create( &thread1, NULL, showart, NULL); getchar(); return 0; } void *showart(NULL) { std::string text; std::ifstream ifs("ascii"); while(!ifs.eof()) { std::getline(ifs,text); printf(text.c_str()); } }
It gives the error:
main.cpp:11:50: error: invalid conversion from ‘void*’ to ‘void* (*)(void*)’ [-fpermissive]
-
kfsone about 8 yearsYou don't need to name
unused
in the definition, which avoids getting an unused warning under some compiler configs.