17

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>\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’
ChrisWue
  • 18,612
  • 4
  • 58
  • 83
lkanab
  • 924
  • 1
  • 7
  • 20

2 Answers2

17

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 ...
pmg
  • 106,608
  • 13
  • 126
  • 198
  • 2
    this is working, but can you please explain why is this necessary? – lkanab Jun 28 '11 at 05:44
  • 3
    @lkanab: according to `man 7 feature_test_macros` this macro (or a few others) can be used to "prevent nonstandard definitions from being exposed" or "expose nonstandard definitions that are not exposed by default". [Appendix B of the POSIX documentation](http://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xsh_chap02.html#tag_22_02_02) speaks a bit about it – pmg Jun 28 '11 at 08:26
  • This didn't work! I'm using Android Studio 2.1 with experimental gradle plugin 0.7.2. Any idea why? – kristoffz Jul 04 '16 at 10:54
5

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

I changed: gcc -std=c99 ...

to this: gcc -std=gnu99 ...

Jon A
  • 101
  • 1
  • 3