Questions tagged [c11]

C11 is the informal name of an older standard version (ISO/IEC 9899:2011) of the C programming language.

Important Note: All C related questions, shall be tagged as , and then as a complement, each should specify the version of the standard it is using. In case of C11, this complement should be the tag.

Detection

A standard macro __STDC_VERSION__ is defined with the value 201112L to indicate that C11 support is available. See corr 1:2012.

Some of the changes since :

  • _Alignas specifier (and optionally the alignas macro)
  • _Alignof operator (and optionally the alignof macro)
  • _Noreturn function specifier (and optionally the noreturn macro)
  • _Generic keyword
  • _Static_assert keyword (and optionally the static_assert macro)
  • _Thread_local storage-class specifier (and optionally the thread_local macro)
  • _Atomic type qualifier
  • _Complex and _Imaginary keywords (and optionally the complex and imaginary macros)
  • once_flag, cnd_t, mtx_t, thrd_t, thrd_start_t, tss_t and tss_dtor_t types
  • char16_t and char32_t types
  • anonymous struct and union support
  • aligned_alloc function
  • quick_exit function
  • gets_s function in much-rejected optional Annex K (see ) as an alternative to the removed gets

More Info:

765 questions
136
votes
7 answers

Why does "sizeof(a ? true : false)" give an output of four bytes?

I have a small piece of code about the sizeof operator with the ternary operator: #include #include int main() { bool a = true; printf("%zu\n", sizeof(bool)); // Ok printf("%zu\n", sizeof(a)); // Ok …
msc
  • 30,333
  • 19
  • 96
  • 184
127
votes
7 answers

Why does auto a=1; compile in C?

The code: int main(void) { auto a=1; return 0; } gets compiled without errors by the MS Visual Studio 2012 compiler, when the file has the .c extension. I have always thought that when you use the .c extension, compilation should be…
lee77
  • 1,463
  • 3
  • 10
  • 13
93
votes
3 answers

Printing null pointers with %p is undefined behavior?

Is it undefined behavior to print null pointers with the %p conversion specifier? #include int main(void) { void *p = NULL; printf("%p", p); return 0; } The question applies to the C standard, and not to C implementations.
Dror K.
  • 1,970
  • 14
  • 26
73
votes
9 answers

Why does "noreturn" function return?

I read this question about noreturn attribute, which is used for functions that don't return to the caller. Then I have made a program in C. #include #include noreturn void func() { printf("noreturn…
msc
  • 30,333
  • 19
  • 96
  • 184
71
votes
3 answers

Syntax and Sample Usage of _Generic in C11

I heard C11 added generics. I've googled a bit, looked at some articles, understood there's a new keyword ( _Generic ) and all. But I can't seem to grasp it all. Is it something like the generics in C# or templates in C++? Can anyone give me a brief…
ApprenticeHacker
  • 19,279
  • 24
  • 94
  • 151
70
votes
2 answers

What is C17 and what changes have been made to the language?

As I was checking news about GCC 8, I saw that they added support for the 2017 version of the C language (not C++17, really C17). But I can't find any information about it on Internet. Is it a new ISO version like C11, or just a codename used by the…
informaticienzero
  • 1,616
  • 1
  • 10
  • 20
68
votes
3 answers

Multi-Threading support in c11

The new C11 standard provides a support for Multi-Threading. My Questions are a bit diversified but definitely answerable. I have had a look at the C11 n1570 draft. It says: support for multiple threads of execution including an improved…
Alok Save
  • 190,255
  • 43
  • 403
  • 518
64
votes
6 answers

What is the default C -std standard version for the current GCC (especially on Ubuntu)?

When I ask to see the current version of cc I get this. $ cc --version cc (Ubuntu/Linaro 4.7.2-2ubuntu1) 4.7.2 Copyright (C) 2012 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not…
ncmathsadist
  • 4,227
  • 3
  • 26
  • 40
62
votes
4 answers

Is type-punning through a union unspecified in C99, and has it become specified in C11?

A number of answers for the Stack Overflow question Getting the IEEE Single-precision bits for a float suggest using a union structure for type punning (e.g.: turning the bits of a float into a uint32_t): union { float f; uint32_t u; }…
sfstewman
  • 5,303
  • 1
  • 16
  • 25
59
votes
6 answers

When are anonymous structs and unions useful in C11?

C11 adds, among other things, 'Anonymous Structs and Unions'. I poked around but could not find a clear explanation of when anonymous structs and unions would be useful. I ask because I don't completely understand what they are. I get that they are…
griotspeak
  • 12,532
  • 12
  • 38
  • 54
59
votes
6 answers

Does &((struct name *)NULL -> b) cause undefined behaviour in C11?

Code sample: struct name { int a, b; }; int main() { &(((struct name *)NULL)->b); } Does this cause undefined behaviour? We could debate whether it "dereferences null", however C11 doesn't define the term "dereference". 6.5.3.2/4 clearly…
M.M
  • 130,300
  • 18
  • 171
  • 314
58
votes
7 answers

Does any C library implement C11 threads for GNU/Linux?

There have been a lot of questions about C11 and C11 threading, but I don't see a definitive answer anywhere: Does any C library implement the C11 threading interface usable on GNU/Linux-like? e.g., provide the "optional" and the thread…
hoc_age
  • 1,725
  • 1
  • 14
  • 27
44
votes
4 answers

Are there any plans for a future C standard after C11?

I searched on the open standards website, particularly the C working group homepage but only found information about C11. They seem to have regular meetings and discuss different features and extensions, but they never actually mention a future C…
Jens
  • 5,066
  • 5
  • 46
  • 64
43
votes
2 answers

Why does C++11 not support anonymous structs, while C11 does?

C11 supports anonymous structures, like so: struct Foo { struct { size_t x, y; }; }; struct Foo f; f.x = 17; f.y = 42; Basically, the members of such a struct are treated as if they were members of the enclosing struct or union…
Jeff Walden
  • 6,508
  • 2
  • 35
  • 54
40
votes
4 answers

How to enable c11 on later versions of gcc?

I currently use gcc 4.6.3. My understanding is that gcc by default uses the gnu89 standard and I would like to enable C11, the latest C standard. I tried: [pauldb@pauldb-laptop test ]$ gcc -std=c11 -o test test.c cc1: error: unrecognised command…
Paul Baltescu
  • 1,765
  • 4
  • 21
  • 28
1
2 3
50 51