title: error: conflicting types for ‘wstat’ in gcc
body: <p>I copied this program from this documentation: <a href="https://docs.oracle.com/cd/E19455-01/806-4750/signals-7/index.html" rel="nofollow noreferrer">https://docs.oracle.com/cd/E19455-01/806-4750/signals-7/index.html</a></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;signal.h&gt;
  #include &lt;sys/wait.h&gt;
  #include &lt;sys/resource.h&gt;
  
  void proc_exit()
  {
          int wstat;
          union wait wstat;
          pid_t   pid;
  
          while (TRUE) {
              pid = wait3 (&amp;wstat, WNOHANG, (struct rusage *)NULL );
              if (pid == 0)
                  return;
              else if (pid == -1)
                  return;
              else
                  printf ("Return code: %d\n", wstat.w_retcode);
          }
  }
  main ()
  {
          signal (SIGCHLD, proc_exit);
          switch (fork()) {
              case -1:
                  perror ("main: fork");
                  exit (0);
              case 0:
                  printf ("I'm alive (temporarily)\n");
                  exit (rand());
              default:
                  pause();
          }
  }
  </code></pre>
  
  <p>When I run <code>gcc main.c</code> I get this error:</p>
  
  <pre><code>main.c: In function ‘proc_exit’:
  main.c:9:13: error: conflicting types for ‘wstat’
    union wait wstat;
               ^~~~~
  main.c:8:6: note: previous declaration of ‘wstat’ was here
    int wstat;
        ^~~~~
  main.c:9:13: error: storage size of ‘wstat’ isn’t known
    union wait wstat;
               ^~~~~
  main.c:12:9: error: ‘TRUE’ undeclared (first use in this function)
    while (TRUE) {
  </code></pre>
  
  <p>As I understand <code>wstat</code> is defined twice. Does it mean that documentation is incorrect? And how it can be fixed?</p>