3

If i compile the below program with std=c99, i get an error, but the program compiles 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’
Jimm
  • 8,165
  • 16
  • 69
  • 118
  • 3
    it requires `_GNU_SOURCE` to compile this with C99 standard. Try with `gcc -std=c99 -D_GNU_SOURCE blah.c -o blah` instead. –  Nov 29 '12 at 03:22
  • @user9000 Why bother with `-std=c99` then? Just use `gcc -std=gnu99` and be done. – melpomene Nov 29 '12 at 03:25
  • @melpomene what does that has to do with it? `_GNU_SOURCE` makes some GNU extensions available. –  Nov 29 '12 at 03:27
  • Sorry didn't notice you said gnu, thought it was 89 ;P –  Nov 29 '12 at 03:29

2 Answers2

2

Because sigset_t is not part of <signal.h> in standard C and you requested strict standards compatibility with -std=c99. That is, a strictly standard C program can do:

#include <signal.h>

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

and expect it to work.

melpomene
  • 84,125
  • 8
  • 85
  • 148
2

sigset_t is not in C99 standard, but it is available in POSIX. You can define _POSIX_SOURCE or _POSIX_C_SOURCE to make sigset_t available.

Here is the definition:

#define _NSIG 64 
#define _NSIG_BPW 32 
#define _NSIG_WORDS (_NSIG / _NSIG_BPW) 

typedef unsigned long old_sigset_t; /* at least 32 bits */ 

typedef struct { 
unsigned long sig[_NSIG_WORDS]; 
} sigset_t; 

Also see What does #define _POSIX_SOURCE mean?

jww
  • 97,681
  • 90
  • 411
  • 885
Aniket Inge
  • 25,375
  • 5
  • 50
  • 78