Results 1 to 3 of 3
|
Enjoy an ad free experience by logging in. Not a member yet? Register.
|
|
-
09-19-2005 #1
- Join Date
- Aug 2005
- Posts
- 19
question about function pointer compile error
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)
In threadhandler.h
#ifdef __cplusplus
extern "C" {
#endif
......
#define MSG1 1
#define MSG2 2
#define MSG3 3
extern void *PrintHello1(void *params);
extern void *PrintHello2(void *params);
extern void *PrintHello3(void *params);
typedef void (*Func)(void *);
struct PrintHi {
int msg;
Func funcptr;
};
#ifdef __cplusplus
}
#endif
In wmain.cpp
......
struct PrintHi PrintHiTable[3] = {
{ MSG1, PrintHello1 },
{ MSG2, PrintHello2 },
{ MSG3, PrintHello3 }
}; // here it is the LINE 42
int main(int argc, char *argv[])
{
......
for (i=0; i< NUM_THREADS; i++) {
......
pthread_create(&threads[i], NULL, PrintHiTable[i].funcptr, (void *) &thread_data_array[i]); // here it is the LINE 97
}
}
Please let me know if you have any good solution.
Thanks.
-
09-19-2005 #2
Shouldn't you be using:
Code:typedef void Func(void *); struct PrintHi { int msg; Func* funcptr; };
Linux user #126863 - see http://linuxcounter.net/
-
09-19-2005 #3
- Join Date
- Nov 2004
- Location
- New York
- Posts
- 150
Code:invalid conversion from `void*(*)(void*)' to `void (*)(void*)'
Code:extern void *PrintHello1(void *params); extern void *PrintHello2(void *params); extern void *PrintHello3(void *params); typedef void (*Func)(void *);
\"Nifty News Fifty: When news breaks, we give you the pieces.\" - Sluggy Freelance