2

I using c thread.

I want to using string argument.

in my source

int main(int argc, char **argv){
  pthread_t thread[1];
  pthread_create(&thread[0], NULL, thread_A, (void *) argv[0]);
  pthread_join(thread[0], NULL)
}

void * thread_A(void * arg){
  char argv[100] = {0};
  strcpy(argv, (char *) arg);
}

when comfile this warning like this

pthread.h:225:12: note: expected 'void * (*)(void *)' but argument is of type 'void * (*)(char **)'

so I use (void *)&argv[0]. but this is error too.

what can I try?

2
  • 1
    The warning is talking about the third argument, the function pointer, it seems that thread_A is in reality a void *thread_A(char **data). It has nothing to do with the forth parameter. Commented Mar 26, 2018 at 1:29
  • I use this, but warning... thank you answer Commented Mar 28, 2018 at 2:26

1 Answer 1

4

Doing

pthread_create(&thread[0], NULL, thread_A, (void *) argv[0]);

and even without the cast

pthread_create(&thread[0], NULL, thread_A, argv[0]);

would be perfectly fine if you want to pass a string as an argument. But the warning you are seeing

pthread.h:225:12: note: expected void * (*)(void *) but argument is of type void * (*)(char **)

is not talking about the forth parameter (the argument to the thread function), it's about the third parameter: the function pointer. In this case is says that the function you are passing has this signature:

void *thread_A(char **arg);

when it's expecting a

void *thread_A(void *arg);

The code you posted doesn't generate the warning you've posted and I assume that the code you are really using declares thread_A as a void * (*)(char **) and not as void * (*)(void*). So check you code carefully.

So the real cast you are looking for would be

pthread_create(&thread[0], NULL, (void * (*)(void*)) thread_A, argv[0]);
Sign up to request clarification or add additional context in comments.

1 Comment

I got solving problem using you answer thank for you help.

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.