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
35
votes
3 answers

Latest changes in C11

C1x has become ISO/IEC 9899:2011 aka C11. Does anyone know what changes (if any) there are in the Standard from the April 2011 draft n1570? ETA: There are the Committee minutes from London (March 2011) (which should be included in n1570) here, and…
J. C. Salomon
  • 3,693
  • 2
  • 26
  • 36
35
votes
2 answers

difference between c99 and c11

I am learning c, presently. The book I read is C99 based. I want to update my knowledge to C11 after finishing this book, or change resource if there is a major difference. Thus, what I ask is for is an explanation or resource to update my…
34
votes
1 answer

Understanding the C11 type hierarchy

I would like to fully understand type hierarchy of the C11 language and present it graphically (a tree diagram would be perfect). The standard does not provide any figure for this issue – there are 30 points describing individual types and relations…
Krzysztof Abramowicz
  • 1,516
  • 1
  • 12
  • 29
32
votes
2 answers

What is the __STDC_VERSION__ value for C11?

I know that compilers use __STDC__ to indicate that a compiler is standard C and, from, there, you can use __STDC_VERSION__ to figure out which level of the standard you're using. I also know that C90 had no value, C90 amendment 1 had 199401L and…
paxdiablo
  • 772,407
  • 210
  • 1,477
  • 1,841
32
votes
2 answers

Is memcpy(&a + 1, &b + 1, 0) defined in C11?

This question follows this previous question about the definedness of memcpy(0, 0, 0), which has been conclusively determined to be undefined behavior. As the linked question shows, the answer hinges on the contents of C11's clause 7.1.4:1 Each of…
Pascal Cuoq
  • 75,447
  • 6
  • 144
  • 260
32
votes
5 answers

Are these compatible function types in C?

Consider the following C program: int f() { return 9; } int main() { int (*h1)(int); h1 = f; // why is this allowed? return h1(7); } According to the C11 Standard, Sec. 6.5.16.1, in a simple…
Steve Siegel
  • 484
  • 4
  • 11
30
votes
1 answer

What are those strange array sizes [*] and [static] in C99?

Apparently the following function prototypes are valid in C99 and C11: void foo(int a[const *]); void bar(int a[static volatile 10]); What is the purpose of those strange subscript notations *, static, and CV qualifiers? Do they help distinguish…
Kerrek SB
  • 428,875
  • 83
  • 813
  • 1,025
29
votes
4 answers

C11 in GCC?

I’m trying to compile some C11 code using thread.h, but I can’t. I've recompiled GCC (running 4.6.2 now), and I’m trying to compile with gcc -std=c1x file.c -o file. I can do this in g++ (using the thread library, that is) but I can’t in C. Is…
Dervin Thunk
  • 17,583
  • 26
  • 110
  • 202
28
votes
5 answers

What precautions should I take to make a memory pool that does not invoke undefined behavior?

My initial problem is that I have, on a project, several objects which share a lifetime (i.e., once I free one of them, I'll free them all), then I wanted to allocate a single block of memory. I have arrays of three different object types, struct…
paulotorrens
  • 2,115
  • 20
  • 24
28
votes
4 answers

How to extract the source filename without path and suffix at compile time?

Using both gcc with -std=c11 and g++ with -std=c++14. E.g. for a file named src/dir/Hello.cxx it should expand to something like e.g.: const char basename[] = "Hello"; or const char basename[] = getStaticBasename(__FILE__); as where…
Joe
  • 2,670
  • 3
  • 34
  • 49
28
votes
4 answers

C11 GCC threads.h not found?

The following code #include Gives me this error: fatal error: threads.h: No such file or directory Using the latest GCC and Clang with -std=c11. Is C11 threading not supported by GCC and Clang? Or is there a hack (or something to…
lucasart
  • 353
  • 1
  • 4
  • 11
27
votes
1 answer

How to go from fopen to fopen_s

Visual Studio is complaining about fopen. I can't find the proper syntax for changing it. I have: FILE *filepoint = (fopen(fileName, "r")); to FILE *filepoint = (fopen_s(&,fileName, "r")); What is the rest of the first parameter?
beatleman
  • 543
  • 2
  • 5
  • 11
26
votes
3 answers

Can a void-returning function g return f(); when f returns void?

Consider the following snippet: void f(void); void g(…) { … return f(); … } Is this return f(); valid according to C11? I am not advocating using this pattern: if it works at all, it is obviously equivalent to f(); return; (where the return;…
Pascal Cuoq
  • 75,447
  • 6
  • 144
  • 260
25
votes
1 answer

What are the semantics of overlapping objects in C?

Consider the following struct: struct s { int a, b; }; Typically1, this struct will have size 8 and alignment 4. What if we create two struct s objects (more precisely, we write into allocated storage two such objects), with the second object…
BeeOnRope
  • 51,419
  • 13
  • 149
  • 309
25
votes
3 answers

Is int main() { } (without "void") valid and portable in ISO C?

The C standard specifies two forms of definition for main for a hosted implementation: int main(void) { /* ... */ } and int main(int argc, char *argv[]) { /* ... */ } It may be defined in ways that are "equivalent" to the above (for example, you…
Keith Thompson
  • 230,326
  • 38
  • 368
  • 578
1
2
3
50 51