C – Why can’t I declare sigset_t with std=c99?

Why can’t I declare sigset_t with std=c99?… here is a solution to the problem.

Why can’t I declare sigset_t with std=c99?

If I compile the program

below with std=c99, I get an error, but the program compiles just fine without the c99 flag. Why?

#include <signal.h>
void x()
{
    sigset_t dd;
}

int main(void)
{
    x();
    return 0;
}

jim@cola temp]$ gcc -std=c99 blah.c -o blah
blah.c: In function ‘x’:
blah.c:9: error: ‘sigset_t’ undeclared (first use in this function)
blah.c:9: error: (Each undeclared identifier is reported only once
blah.c:9: error: for each function it appears in.)
blah.c:9: error: expected ‘; ’ before ‘dd’

Solution

Because sigset_t does not belong to <signal.h> in standard C, you require strict compatibility with the -std=c99 standard. That is, a strictly standard C program can do it:

#include <signal.h>

int sigset_t;
int main(void) { return 0; }

And expect it to work.

Related Problems and Solutions