1

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
  }

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

2 Comments

didnt think of that, why didn't the cast work in the pthread_create ?
You were casting the fourth argument of pthread_create whereas the problem is about the third one: the function pointer. The prototype of pthread_create requires the third argument to be of type void * (*)(void *).
0

The compilation error is because pthread_create expects void *output_results(void *bins), but you have int *bins.

Also, the declaration of output_results you're using does not match its definition.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.