2
votes

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?

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. - Pablo
I use this, but warning... thank you answer - 최우영

1 Answers

4
votes

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]);