问题描述
我有这个最小的helloworld,并扩展了ucontext.h
:
I have this minimal helloworld, extended with an include of ucontext.h
:
#include <ucontext.h>
#include <stdio.h>
int main(int argc, char** argv) {
printf ("hello world!\n");
return 0;
}
它使用gcc-4.9(gcc -c hw.c -Wall
)进行编译而不会发出警告.
It compiles without warning with gcc-4.9 (gcc -c hw.c -Wall
).
但是,如果我切换到c11标准(gcc -std=c11 -c hw.c -Wall
),则会出现以下错误:
But if I switch to the c11 standard (gcc -std=c11 -c hw.c -Wall
), I get the following error:
$ gcc -std=c11 -c hw.c -Wall
In file included from /usr/include/ucontext.h:26:0,
from hw.c:1:
/usr/include/x86_64-linux-gnu/sys/ucontext.h:137:5: error: unknown type name ‘stack_t’
stack_t uc_stack;
^
我的第一个想法是glibc不支持c11.对此进行谷歌搜索并没有发现可用的信息.是什么情况?
My first idea is that glibc doesn't support c11. Googling for that didn't reveal usable information. What is the case?
(我在gcc-4.9中使用glibc-2.19.这是一个debian jessie,amd64.)
(I use glibc-2.19 with gcc-4.9. It is a debian jessie, amd64.)
推荐答案
-std=c11
是C11标准兼容模式. <ucontext.h>
严格不是C11的一部分(请参阅Stas的答案).
-std=c11
is C11 standard compliant mode. <ucontext.h>
isn't strictly part of C11 (see Stas's answer).
要使用这些标头,请使用扩展模式-std=gnu11
或根据您要支持的平台(_POSIX_C_SOURCE
,_BSD_SOURCE
,_XOPEN_SOURCE
,_GNU_SOURCE
或其他)定义适当的宏.
To use these headers either use extension mode -std=gnu11
or define appropriate macro depending on which platform do you intend to support (_POSIX_C_SOURCE
, _BSD_SOURCE
, _XOPEN_SOURCE
, _GNU_SOURCE
or maybe others).
有关详细信息,请参见此页面有关启用功能的宏.
这篇关于Glibc-ucontext.h中的错误,但仅与-std = c11有关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!