Search code examples
cgccglibcc11gcc4.9

Glibc - error in ucontext.h, but only with -std=c11


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;
}

It compiles without warning with gcc-4.9 (gcc -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;
     ^

My first idea is that glibc doesn't support c11. Googling for that didn't reveal usable information. What is the case?

(I use glibc-2.19 with gcc-4.9. It is a debian jessie, amd64.)


Solution

  • -std=c11 is C11 standard compliant mode. <ucontext.h> isn't strictly part of C11 (see Stas's answer).

    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).

    See this page for more info about feature-enabling macros.