passing arg 3 of `pthread_create' from incompatible pointer type
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.
Re: Re: passing arg 3 of `pthread_create' from incompatible pointer type
freegianghu, you can't return NULL; from a function with a void return-type.
The problem is that sendThread is defined both as a function (by a forward declaration) and as a variable. The variable masks the definition of the function, and so both sendThread arguments passed to pthread_create are of type pthread_t.
Since the third argument to pthread_create is supposed to be a callback function, not a pthread_t, this won't compile.
Re: Re: Re: passing arg 3 of `pthread_create' from incompatible pointer type
Quote:
Originally posted by rjlee freegianghu, you can't return NULL; from a function with a void return-type.
The problem is that sendThread is defined both as a function (by a forward declaration) and as a variable. The variable masks the definition of the function, and so both sendThread arguments passed to pthread_create are of type pthread_t.
Since the third argument to pthread_create is supposed to be a callback function, not a pthread_t, this won't compile.
Sorry, I made a mistake . Its should be void *sendThread(void *rxLength)
Originally Posted by http://opengroup.org/onlinepubs/007908799/xsh/pthread_create.html
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
void *(*start_routine)(void*), void *arg);
From this, argument 3 should be a pointer to a function of the form
Code:
void * foo(void* bar)
but your passing it "myThread", which has signature
Code:
void myThread(void *arg)
So change return type from "void" to "void*", and of course add the "return" logic in the function.
For the "undefined reference" errors this usually means you're not linking to the library that contains the actual object code. It depends on your compiler, which you haven't told us, but for "gcc" I think you can pass "-pthread" as an argument when compiling. This should get rid of the second "undefined reference" error also.
From this, argument 3 should be a pointer to a function of the form
Code:
void * foo(void* bar)
but your passing it "myThread", which has signature
Code:
void myThread(void *arg)
So change return type from "void" to "void*", and of course add the "return" logic in the function.
For the "undefined reference" errors this usually means you're not linking to the library that contains the actual object code. It depends on your compiler, which you haven't told us, but for "gcc" I think you can pass "-pthread" as an argument when compiling. This should get rid of the second "undefined reference" error also.
Thank you for reply.
I am using eclipse cdt as a compiler and ubuntu 9.04 as a operating system. When I compile code with terminal , it worked fine.
Hi there;
I've encountered with the same problem in my code with some extra problems.Here are the code :
Code:
...
[SIZE="6"] //below code gives error: passing argument 3 of ‘pthread_create’ from incompatible pointer type
...
//below code gives error: undefined reference to `pthread_join'
ret = pthread_join(threadIds[i] , NULL );
...
I looked at my code properly but I could not find error.
Thanks in advance!
"Undefined reference" is a linker error, not a compiler error. It means that your code is correct (at least syntactically) but GCC can't find the definition of the pthread_create and pthread_join functions.
You probably need to tell gcc to link against the libpthread.so (or libpthread.a) library. The best way to do this is by adding a command-line argument like -lpthread.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.