C (gcc) 警告:调用 pthread_cleanup_push() 时从不兼容的指针类型初始化 [英] C (gcc) warning: initialization from incompatible pointer type when calling pthread_cleanup_push()

查看:101
本文介绍了C (gcc) 警告:调用 pthread_cleanup_push() 时从不兼容的指针类型初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ubuntu Linux 9.04 下的 gcc 版本 4.3.3,以防万一.

gcc version 4.3.3 under Ubuntu Linux 9.04 in case that is relevant.

这是违规代码:

pthread_cleanup_push(ctl_cleanup, NULL);

ctl_cleanup() 定义为

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);

其中 m 是 pthread_mutex_t 类型.警告内容如下:

where m is of type pthread_mutex_t. The warning reads:

警告:从不兼容的指针类型初始化

warning: initialization from incompatible pointer type

我不明白.我已经使用 void 指针传递了其他东西(例如,在将参数传递给 pthread 时)而没有发出警告.有人可以帮我吗?

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?

推荐答案

void ctl_cleanup(void *arg);

以上就是你要找的原型.它返回 void,而不是指向 void 的指针.

The above is the prototype you are looking for. It returns void, not a pointer to void.

函数中额外的 * 是因为它需要一个指向函数的指针,该函数接受一个返回 void 的 void* 参数.

The extra * in the function is because it takes a pointer to a function taking one void* argument returning void.

这篇关于C (gcc) 警告:调用 pthread_cleanup_push() 时从不兼容的指针类型初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆