错误:‘;的类型冲突;wstat&x2019;在gcc中

错误:‘;的类型冲突;wstat&x2019;在gcc中,c,gcc,compiler-errors,sigchld,C,Gcc,Compiler Errors,Sigchld,我从以下文档中复制了此程序: 据我所知,wstat定义了两次。这是否意味着文档不正确?以及如何修复它?是的,代码刚刚被破坏。我不知道union wait wstat的意图是什么。可能是文档作者的复制粘贴错误。谁知道呢。依我看,代码一般写得很差 无论如何,下面是代码实际要做的: int wstat; pid_t pid; while (1) { pid = wait3(&wstat, WNOHANG, NULL); if (pid == 0 || pid == -1)

我从以下文档中复制了此程序:


据我所知,
wstat
定义了两次。这是否意味着文档不正确?以及如何修复它?

是的,代码刚刚被破坏。我不知道
union wait wstat的意图是什么。可能是文档作者的复制粘贴错误。谁知道呢。依我看,代码一般写得很差

无论如何,下面是代码实际要做的:

int wstat;
pid_t pid;

while (1) {
    pid = wait3(&wstat, WNOHANG, NULL);
    if (pid == 0 || pid == -1)
        return;
    printf("Return code: %d\n", wstat);
}
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) {
int wstat;
pid_t pid;

while (1) {
    pid = wait3(&wstat, WNOHANG, NULL);
    if (pid == 0 || pid == -1)
        return;
    printf("Return code: %d\n", wstat);
}