ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I have a program which was coded by mix of c++ and c code, when I test the function pointer in C code, it is ok, but when I try to merge it with C++ code, it give me compile error like this:
gcc -g -Wall -D_GNU_SOURCE -DDEBUG -c wmain.cpp
wmain.cpp:42: invalid conversion from `void*(*)(void*)' to `void (*)(void*)'
wmain.cpp:42: invalid conversion from `void*(*)(void*)' to `void (*)(void*)'
wmain.cpp:42: invalid conversion from `void*(*)(void*)' to `void (*)(void*)'
wmain.cpp: In function `int main(int, char**)':
wmain.cpp:97: invalid conversion from `void (*)(void*)' to `void*(*)(void*)'
gmake: *** [wmain.o] Error 1
Here it is the snapshot of my two files (one is the header file to define the function pointer)
Originally posted by itsme86 You want your functions to return void instead of void *. So change:
extern void *PrintHello1(void *params);
to:
extern void PrintHello1(void *params);
...for all 3 functions.
I was going to suggest that at first too, but apparently pthread_create wants a start routine that returns void*.... It uses that return value as a parameter to pthread_exit(void *value_ptr);
Neither two of the suggestion work, since the PrintHello1 (to 3) will be thread function, so it must be defined as void *, but thanks for your reply.
I still wait to find the solution.
My suggestion doesn't suggest changing the return type of your PrintHello1. Your typedef is a typedef to a function that returns a void not a void*, so you have a mismatch there.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.