当前位置: 动力学知识库 > 问答 > 编程问答 >

c - POSIX sigevent not compiling with c11

问题描述:

I have simple app in C that is using POSIX struct sigevent.

#include <signal.h>

int main(int argc, char *argv[])

{

struct sigevent sig_event;

return 0;

}

When I compile it like this:

gcc test.c

it is fine. When I force C11 mode, it fails:

gcc test.c --std=c11

test.c: In function ‘main’:

test.c:5:21: error: storage size of ‘sig_event’ isn’t known

struct sigevent sig_event;

I'm using gcc 5.2.1 on Ubuntu 15.10. Any ideas what is causing those errors? This problem first occured when I tried to compile example from manual for timer_create() function. Situation was the same, except for much more errors.

网友答案:

The header <signal.h> is part of standard C. But POSIX adds more to it. Since struct sigevent is not C but in POSIX -std=c11 disables (probably an ifdef somewhere) it.

gcc test.c

works because gcc by default enables certain level of POSIX functions and a lot GNU extensions.

Compile it with:

gcc -std=c11 -D_POSIX_C_SOURCE=200809 file.c
分享给朋友:
您可能感兴趣的文章:
随机阅读: