title: Passing argc and argv to a thread in c
body: <p>Im trying to code a chat in C with a graphical interface.
  On one side, I have a client for my chat, on the other side I have a GTK app to display my chat.
  To run them both at the same time, I'll be using pthread (open to other suggestions tho).</p>
  
  <p>My problem is that I need both argc and argv in order for my client to work properly. From what I saw, pthread_create() takes as argument a function to execute and only one argument. I saw from other topics that I could use a data structure to contain them both, but I can't seem to cast them properly. Here is what I have : </p>
  
  <pre><code>typedef struct {
      int *argc;
      char ** argv;
  } args_list;
  
  void * simple_client(void * arg){
      int argc = (int) arg-&gt;argc;
      char * argv[] = (char *) arg-&gt;argv;
      printf("in thread : %d / %s, %s \n", argc, argv[0], argv[1]);
  
      return 0;
  }
  
  int main(int argc, char * argv[])
  {   
      printf("int main : %d / %s, %s \n", argc, argv[0], argv[1]);
      args_list * args = malloc(sizeof *args);
      args-&gt; argc = &amp;argc;
      args-&gt; argv = &amp;argv;
  
      pthread_t thread1;
  
      if (pthread_create(&amp;thread1, NULL, simple_client, args)) {
          perror("pthread_create");
          return EXIT_FAILURE;
      }
      if (pthread_join(thread1, NULL)) {
          perror("pthread_join");
          return EXIT_FAILURE;
      }
      return EXIT_SUCCESS;
  }
  </code></pre>
  
  <p>From this, I get : error: request for member ‘argc’ in something not a structure or union from int argc = (int) arg->argc; and the same with argv from char * argv[] = (char *) arg->argv;</p>
  
  <p>What would be causing these errors ? And do you think this is a good way of implementating an online chat with a GTK gui ?</p>
  
  <p>Thanks in advance</p>