3

以下のプログラムを std=c99 でコンパイルすると、エラーが発生しますが、プログラムは c99 フラグなしで正常にコンパイルされます。なんで?

#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’
4

2 に答える 2

3

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.

于 2012-11-29T03:16:52.203 に答える
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?

于 2012-11-29T03:16:52.580 に答える