çpthread的传递类型为int数组 [英] c pthread passing array of type int

查看:229
本文介绍了çpthread的传递类型为int数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我传递int类型pthread_create的和得到错误的数组:

  histogram.c:138:3:警告:传递的参数3
 从兼容的指针类型'pthread_create的'[默认启用]
  预计'无效*(*)(无效*),但参数的类型为无效*(*)为(int *)'  无效* output_results();
  在pthread_create(安培; T2,NULL,output_results,(无效*)箱);  无效* output_results为(int *箱){
      一些code
  }


解决方案

 无效* output_results(无效*);
在pthread_create(安培; T2,NULL,output_results,(无效*)箱);无效* output_results(无效*数据){
    为int *垃圾箱=(INT *)的数据;
    //一些code
}

错误消息是pretty明确:功能应该是键入无效*(*)(无效*),而不是无效的*(*)(INT *)(加上您的原型为 output_results 不匹配其定义)。

I am passing an array of type int pthread_create and getting error:

  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
  }

解决方案

Should be

void *output_results(void*);
pthread_create(&t2, NULL, output_results, (void *)bins);

void *output_results(void *data) {
    int *bins = (int*)data;
    // some code
}

The error message is pretty clear: the function should be of type void * (*)(void *) and not void * (*)(int *) (plus your prototype for output_results was not matching its definition).

这篇关于çpthread的传递类型为int数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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