473,505 Members | 13,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

another "does not match ‘void* (*)(void*)’" error

7 New Member
Hi all,

I have encountered the above said error for some time. I have researched for possible solutions and have discovered that the error means that the function that I am calling as a thread is a member function. I have already declared the function as a global function, but yet the error still appears. Can anyone help me out here? The code is below. Thx in advance.

Expand|Select|Wrap|Line Numbers
  1. #include <pthread.h>
  2. #include <stdlib.h>
  3. #include <stdio.h>
  4.  
  5. bool orderStop=true;
  6. bool firstTime=true;
  7. bool stopRobo=false;
  8.  
  9. void *detectKey(void *arg)
  10. {
  11.     int y;
  12.     std::cin >> y;
  13.     while (y != 1)
  14.     {
  15.         orderStop = true;
  16.     stopRobo = true;
  17.     }
  18.     return NULL;
  19.     pthread_exit(0);
  20. }
  21.  
  22. void *detectKey(void *arg);
  23.  
  24. void
  25. MainLoop::run()
  26. {
  27.         pthread_t wait;
  28.         int rc;
  29.    .....
  30.     while ( isActive() )
  31.     {
  32.         try 
  33.         {
  34.             ....
  35.         if (orderStop)
  36.         {
  37.             ....
  38.             // create thread to wait for keyboard input
  39.             rc = pthread_create(&wait,NULL,detectKey,NULL);
  40.         };
  41.         ....
  42.         orderStop = false;
  43.         std::cout <<"\nBoolean orderStop is set at: " << orderStop <<endl;
  44.  
  45.         }
  46.        catch(....){....}
  47.      }
  48. }
  49.  
Feb 26 '10 #1
7 3482
grayMist
12 New Member
cant see any issues in the code as such.
Which compiler are you using?
Can you post the exact error messages from the compiler here along with the concerned code blocks ?
Feb 26 '10 #2
Banfa
9,065 Recognized Expert Moderator Expert
Please post the entire error message which normally gives the type of the object supplied and the type that the function was expecting.
Feb 26 '10 #3
Jianwee
7 New Member
Thx for the reply so far. Here's some info that might help:
I'm running on Ubuntu 9.04.
GCC 4.1.3
G++ 4.1.3

The whole error message is:
error: arguement of type 'void (localnav::MainLoop::)(void*)' does not match 'void* (*)(void*)'

As I am working on ORCA (open source code for robotics), the whole code is too long to be displayed. The code where the error is pointing to is at the pthread_create method in the previous code block.
Feb 26 '10 #4
donbock
2,426 Recognized Expert Top Contributor
The prototype I found for pthread_create is
Expand|Select|Wrap|Line Numbers
  1. int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
  2.     void *(*start_routine)(void*), void *arg);
You pass detectKey as the start_routine argument. Its prototype is
Expand|Select|Wrap|Line Numbers
  1. void *detectKey(void *arg);
I don't see any incompatibility. I don't know why you get an error.

The double-colons in the error message make me think you might be using C++. I'm not aware of any reason C++ would be more persnickety about function pointers than C.

I suggest you take a look inside <pthread.h> and see if your pthread_create has a different prototype than the one I found on the internet.
Feb 26 '10 #5
Banfa
9,065 Recognized Expert Moderator Expert
Does you MainLoop class have a detectKey member function?

You can not pass member functions to functions like pthread_create that require a function pointer unless they are static because a member function has to be called on an object which pthread_create can't do.

If you have an externally declared detectKey function, as your code suggests as well as a detectKey member function in the MainLoop class then you need to make sure you address the correct function using the scope resolution operator (::) like so

rc = pthread_create(&wait,NULL,::detectKey,NULL);
Feb 26 '10 #6
Jianwee
7 New Member
To Banfa: I have already declared the detectKey function at the very beginning of the mainloop.cpp, right below the include, so that should be a global function right? But I will try what you have suggested. Sorry for getting it wrong, I'm only starting out on C++ recently.

To donbock: I will take a look at <pthread.h> as you suggested. Thanks.
Feb 27 '10 #7
Jianwee
7 New Member
Banfa,

Thx a lot! Your method works!
Feb 27 '10 #8

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

Similar topics

15
6828
by: lkrubner | last post by:
I want to give users the power to edit files from an easy interface, so I create a form and a PHP script called "fileUpdate". It does a reasonable about of error checking and prints out some...
5
2059
by: kmunderwood | last post by:
I am trying to combine "if match=" and "when test" I am a newbie, and have made both work separately, but I can not seem to combine them. This is my xml("index.xml")page(I can not change this,...
2
7168
by: S.Peppe | last post by:
Hi there! I'm really new at this game, so please forgive me if my request is at all irritating. I have installed PostgreSQL onto a Debian/Linux machine, and I have just upgraded PostgreSQL via...
1
2502
by: CA | last post by:
I am having a problem getting a pointer to an existing running Excel process on a client machine. Here are some details: 1) I have tested out the code on the development machine and it works...
2
5047
by: Tom | last post by:
I'm getting this error when I try to pass a structure to a dll. An unhandled exception of type 'System.ArgumentException' occured in Test1.exe Additional Information: Type could not be marshaled...
51
3879
by: Tony Sinclair | last post by:
I'm just learning C#. I'm writing a program (using Visual C# 2005 on WinXP) to combine several files into one (HKSplit is a popular freeware program that does this, but it requires all input and...
3
20961
by: sandy | last post by:
I cannot figure this out. I have the following code: <code> Private: /****************************************************************************** CreateList
4
5744
by: zensunni | last post by:
Here's what my code looks like: ======================================= Set RS = Server.CreateObject("ADODB.Recordset") RS.Open "Table", objConn, 1, 3, 2 If Len(Request.Form("AreaID1")) > 0...
1
2337
by: patelxxx | last post by:
Hi Guy's, I'm getting the error: "Username or password did not match" BEFORE I even enter a username and password, can someone help? 1) The site I'm accessing is:...
7
1697
by: phub11 | last post by:
Hi all, I am using "match" to see if elements in one array match elements in another array. My first array is "1.1,1.2,2.1" so I convert it to a string. Next, I have a loop that cycles through...
0
7213
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
7298
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
7366
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...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4698
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1526
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.