C (gcc) warning: initialization from incompatible pointer type when calling pthread_cleanup_push()

让人想犯罪 __ 提交于 2019-12-11 05:29:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!