加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

pthread_create不起作用.传递参数3警告

发布时间:2020-12-13 19:10:25 所属栏目:Linux 来源:网络整理
导读:我正在尝试创建一个线程,从我记得这应该是正确的方法: #include 而我得到的错误是这个: test.c: In function ‘main’: test.c:28: warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type /usr/include/pthread.h:227: note:

我正在尝试创建一个线程,从我记得这应该是正确的方法:

#include 

而我得到的错误是这个:

test.c: In function ‘main’: test.c:28: warning: passing argument 3 of
‘pthread_create’ from incompatible pointer type
/usr/include/pthread.h:227: note: expected ‘void * (*)(void *)’ but
argument is of type ‘void (*)(int)’

我无法更改SimpleThread函数,因此更改参数的类型不是一个选项,即使我已经尝试过它也不起作用.

我究竟做错了什么?

最佳答案
SimpleThread应声明为

void* SimpleThread(void *args) {
}

将参数传递给线程时,最好为它们定义一个结构,将指向该结构的指针传递给void *,然后在函数内部转换回正确的类型.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读