c/c++语言开发共享c pthread传递int类型的数组

我传递一个int pthread_create类型的数组并得到错误:

histogram.c:138:3: warning: passing argument 3 of 'pthread_create' from incompatible pointer type [enabled by default] expected 'void * (*)(void *)' but argument is of type 'void * (*)(int *)' void *output_results(); pthread_create(&t2, NULL, output_results, (void *)bins); void *output_results(int *bins) { some code } 

    应该

     void *output_results(void*); pthread_create(&t2, NULL, output_results, (void *)bins); void *output_results(void *data) { int *bins = (int*)data; // some code } 

    错误消息非常清楚:函数应该是void * (*)(void *)而不是void * (*)(int *) (加上output_results的原型与其定义不匹配)。

    编译错误是因为pthread_create需要void *output_results(void *bins) ,但是你有int *bins

    此外,您正在使用的output_results声明与其定义不匹配。

    需要了解更多c/c++开发分享c pthread传递int类型的数组,也可以关注C/ C++技术分享栏目—计算机技术网(www.ctvol.com)!

      以上就是c/c++开发分享c pthread传递int类型的数组相关内容,想了解更多C/C++开发(异常处理)及C/C++游戏开发关注计算机技术网(www.ctvol.com)!)。

      本文来自网络收集,不代表计算机技术网立场,如涉及侵权请联系管理员删除。

      ctvol管理联系方式QQ:251552304

      本文章地址:https://www.ctvol.com/c-cdevelopment/936068.html

      (0)
      上一篇 2021年11月13日
      下一篇 2021年11月13日

      精彩推荐