473,396 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to fix invalid conversion error while using pthread_create()?

bajajv
152 100+
Hi,
My code is -

Expand|Select|Wrap|Line Numbers
  1. void func1(void* arg)
  2. {
  3.   printf("In child thread.\n");
  4. }
  5.  
  6. int main()
  7. {
  8.   int ret;
  9.   pthread_t tid; 
  10.   void (*start_routine) (void*);
  11.   start_routine = &func1;
  12.   ret = pthread_create(&tid, NULL, start_routine, attr);
  13.   printf("In main thread.\n");
  14.   return 0;
  15. }
  16.  
I am getting the error - Invalid conversion from
void (*) (void*) to void* (*) (void*)
I did not understand why this extra * is coming into picture?
Feb 1 '11 #1

✓ answered by horace1

you are correct, looking again line 10 should be
Expand|Select|Wrap|Line Numbers
  1.   void *(*start_routine) (void*);
  2.  

6 5214
horace1
1,510 Expert 1GB
I think the function should be
Expand|Select|Wrap|Line Numbers
  1. void* func1(void* arg)
  2. {
  3.   printf("In child thread.\n");
  4. }
  5.  
and 10 should be
Expand|Select|Wrap|Line Numbers
  1.   void *start_routine (void*);
  2.  
Feb 1 '11 #2
bajajv
152 100+
well no, it is not working.

if we change line 10, will start_routine be still a function pointer, because it doesn't have that * now inside the braces?
Feb 1 '11 #3
horace1
1,510 Expert 1GB
you are correct, looking again line 10 should be
Expand|Select|Wrap|Line Numbers
  1.   void *(*start_routine) (void*);
  2.  
Feb 1 '11 #4
bajajv
152 100+
I did not understood one thing.. why do i need to make my func1 returning void* and the function pointer type as void* (*start_routine) (void*)?
Feb 1 '11 #5
horace1
1,510 Expert 1GB
if you look at the specification
http://pubs.opengroup.org/onlinepubs...ad_create.html

of pthread_create
Expand|Select|Wrap|Line Numbers
  1. int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
  2.     void *(*start_routine)(void*), void *arg);
  3.  
the third parameter is a pointer to a function which takes a single parameter pointer to void and returns a pointer to void as a function result. Hence start_routine must be
Expand|Select|Wrap|Line Numbers
  1. void* func1(void* arg)
  2.  
Feb 1 '11 #6
bajajv
152 100+
hmm.. I should have checked that first..
thanks for the help...
Feb 1 '11 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

30
by: Tim Johansson | last post by:
I'm new to C++, and tried to start making a script that will shuffle an array. Can someone please tell me what's wrong? #include <iostream.h> #include <string.h> int main () {...
6
by: Thomas Barth | last post by:
Hi, I'm new to windows programming and still reading a book about windows-programming with C++. I copied the following code from the book into my ide (Eclipse/CDT) to comprehend the code, but two...
8
by: Abhijit Bhadra | last post by:
Hi , I am using gcc version 3.3.2. While compiling this code struct sockaddr_in *CBaseSocket::GetSocketName() { socklen_t iLen; cCriticalSocket.Lock(); //...
5
by: Martin Jørgensen | last post by:
Hi, I'm using this alloc_mem-function (by Michael Mair): - - - - - - - - - - - - - - - - - - - - - - - - void *alloc_mem (size_t num_elems, size_t elem_size, char *filename, int line,...
0
by: | last post by:
Hi all, running the following code as an console application: #include <locale> #include <iostream> #include <sstream> #include <tchar.h> using namespace std;
2
by: tkirankumar | last post by:
Hi all, uname -a SunOS cbmrsd1a1 5.10 Generic_118833-17 sun4us sparc FJSV,GPUZC-M g++ -v Reading specs from /usr/local/lib/gcc-lib/sparc-sun-solaris2.10/3.3.2/specs Configured with:...
3
by: fazulu deen | last post by:
Hi all, For the following code : file_ptr = fopen("pass_fail.txt", "a"); // error line 393 fdisplay(file_ptr, "Test Passed"); fclose(file_ptr);
11
by: batmanfreeze | last post by:
I am using C# in .Net 1.1, and need to access the 'Client' Property of TcpClient, so I created a derived class to do this based upon the Microsoft Sample, located at:...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.