简体   繁体   English

c pthread传递int类型的数组

[英]c pthread passing array of type int

I am passing an array of type int pthread_create and getting error: 我正在传递一个类型为pthread_create int的数组并收到错误:

  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). 错误消息非常清楚:该函数的类型应该为void * (*)(void *)而不是void * (*)(int *) (加上output_results的原型与它的定义不匹配)。

The compilation error is because pthread_create expects void *output_results(void *bins) , but you have int *bins . 编译错误是因为pthread_create预期为void *output_results(void *bins) ,但是您有int *bins

Also, the declaration of output_results you're using does not match its definition. 另外,您使用的output_results声明与其定义不匹配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM