问题
gcc version 4.3.3 under Ubuntu Linux 9.04 in case that is relevant.
This is the offending code:
pthread_cleanup_push(ctl_cleanup, NULL);
with ctl_cleanup() defined as
void* ctl_cleanup(void *arg);
There are other instances where this warning pops up, in similar circumstances. The warning also appears if I call something like
pthread_cleanup_push(pthread_mutex_unlock, (void *)&m);
where m is of type pthread_mutex_t. The warning reads:
warning: initialization from incompatible pointer type
I don't understand. I've passed other things around using void pointers (e.g. when passing arguments to a pthread) without that warning. Can someone help me out?
回答1:
void ctl_cleanup(void *arg);
The above is the prototype you are looking for. It returns void, not a pointer to void.
The extra * in the function is because it takes a pointer to a function taking one void* argument returning void.
来源:https://stackoverflow.com/questions/6119140/c-gcc-warning-initialization-from-incompatible-pointer-type-when-calling-pthr