Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

c - struct sigaction incomplete error

Although including <signal.h> I get an error saying that struct sigaction is an incomplete type.

I have no Idea what to do with it.

Please help

#include <signal.h>
struct sigaction act;

int main(int argc, char** argv)
{
    int depth;

    /* validate arguments number*/
    if(argc < 2)
    {
        printf("fatal error: please use arguments <MaxChild> <MaxDepth>
");
        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’
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Just

#define _XOPEN_SOURCE 700

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

gcc ... -D_XOPEN_SOURCE=700 ...

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...