struct sigaction incomplete error

匿名 (未验证) 提交于 2019-12-03 01:32:01

问题:

Although including I get an error saying that struct sigaction is an incomplete type.

I have no Idea what to do with it.

Please help

#include  struct sigaction act;  int main(int argc, char** argv) {     int depth;      /* validate arguments number*/     if(argc  \n");         exit(1);     }      /* register the realtime signal handler for sigchld*/  /*173*/     memset(&act,0,sizeof(act));     act.sa_handler = sigproc;     sigaction(SIGCHLD,  /* signal number whose action will be changed */              &act,      /* new action to do when SIGCHLD arrives*/              NULL);     /* old action - not stored */       srand(time(NULL));     depth = rand() % atoi(argv[2]); /* [0 maxDepth]*/      RecursiveFunc(atoi(argv[1]), depth);      return 0; } 

The error messages:

proc.c: In function ‘main’: proc.c:173:22: error: invalid application of ‘sizeof’ to incomplete type ‘struct sigaction’  proc.c:174:2: error: invalid use of undefined type ‘struct sigaction’ cc1: warnings being treated as errors proc.c:175:2: error: implicit declaration of function ‘sigaction’ 

回答1:

Just

#define _XOPEN_SOURCE 

before any other line in your code, or compile with the -D option to define the preprocessor symbol

gcc ... -D_XOPEN_SOURCE ... 


回答2:

I resolved this by changing the C standard that I was using with gcc.

I changed: gcc -std=c99 ...

to this: gcc -std=gnu99 ...



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!