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:

875 questions
22
votes
2 answers

__func__ outside function definition

What should happened if we use predefined variable __func__ outside a function in C (C99 / C11) and C++? #include const char* str = __func__; int main(void) { printf("%s", str); return 0; } gcc 4.7.2 only give a warning (with…
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242
22
votes
3 answers

Use of _Noreturn in C11

Possible Duplicate: What is the point of the Noreturn attribute? C11 introduced the _Noreturn attribute to indicate that a function never returns. Except for documentation value in the source code, what other benefits do the attribute provide,…
user1255770
  • 1,572
  • 1
  • 12
  • 18
22
votes
4 answers

What is gets() equivalent in C11?

From cplusplus.com The most recent revision of the C standard (2011) has definitively removed this function from its specification The function is deprecated in C++ (as of 2011 standard, which follows C99+TC3). I just wanted to know what is…
Shash
  • 4,160
  • 8
  • 43
  • 67
21
votes
3 answers

initialization of anonymous structures or unions in C1X

I have the following question: How are anonymous structures (or unions) properly initialized according to the current C1X draft? Is this legal: struct foo { int a; struct { int i; int j; }; int b; }; struct foo f = {…
jmuc
  • 1,551
  • 1
  • 14
  • 16
20
votes
7 answers

What is the type of a bitfield?

I can't find anywhere in the C standard where this is specified. For example, in struct { signed int x:1; } foo; is foo.x an lvalue of type int, or something else? It seems unnatural for it to be an lvalue of type int since you cannot store any…
R.. GitHub STOP HELPING ICE
  • 208,859
  • 35
  • 376
  • 711
19
votes
3 answers

C11 anonymous structs via typedefs?

Anonymous structs have been added in the C11 standard, so typedef struct { struct {int a, b}; int c; } abc_struct; is valid and standard. Is it also within the standard to use a typedef in place of the full struct declaration?…
bk.
  • 6,068
  • 2
  • 24
  • 28
19
votes
1 answer

Have anonymous structs and unions in C11 been incorrectly described?

Sayeth the C standard, regarding anonymous structs and unions: 6.7.2.1 p13. An unnamed member whose type specifier is a structure specifier with no tag is called an anonymous structure; an unnamed member whose type specifier is a union…
Sneftel
  • 40,271
  • 12
  • 71
  • 104
19
votes
2 answers

Returning a local partially initialized struct from a function and undefined behavior

(By partially initialized I mean defined as uninitialized and one of its members is set to some valid value, but not all of them. And by local I mean defined with automatic storage duration. This question only talks about those.) Using an automatic…
2501
  • 25,460
  • 4
  • 47
  • 87
19
votes
4 answers

Why can't I "goto default;" or "goto case x;" within a switch selection structure?

Section 6.8.1 of C11 or C99, or section 3.6.1 of C89 all seem to indicate that default and case x (where x is some constant-expression) are examples of labeled statements, along-side identifier:-style labels that are suitable for use with goto. I'm…
autistic
  • 1
  • 3
  • 35
  • 80
19
votes
1 answer

Standard way in C11 and C++11 to convert UTF-8?

C11 and C++11 both introduce the uchar.h/cuchar header defining char16_t and char32_t as explicitly 16 and 32 bit wide characters, added literal syntax u"" and U"" for writing strings with these character types, along with macros __STDC_UTF_16__ and…
Brian Campbell
  • 322,767
  • 57
  • 360
  • 340
19
votes
1 answer

Why do some C standard headers begin with 'std' while others don't?

For example, in the new C11 standard there have been added stdalign.h and threads.h. Why not stdthreads.h or align.h? Is it to avoid collisions with existing libraries and system headers?
szx
  • 6,433
  • 6
  • 46
  • 67
19
votes
1 answer

Lifetime of temporary objects in C11 vs C99

I am trying to decipher a note that led to a change between C99 and C11. The change proposed in that note ended up in C11's 6.2.4:8, namely: A non-lvalue expression with structure or union type, where the structure or union contains a member…
Pascal Cuoq
  • 79,187
  • 7
  • 161
  • 281
18
votes
5 answers

Compilers that support C11

I was wondering if there are any compilers that support a considerable amount of the new C11 standard. Looking for features like Generic Selection etc. Any suggestions?
ApprenticeHacker
  • 21,351
  • 27
  • 103
  • 153
18
votes
2 answers

Is there any option to switch between C99 and C11 C standards in Visual Studio?

I am new to Visual Studio Environment and I am using VS2017 Pro. I wanted to write simple program in C and compiled with both c99 and c11 standards. In Visual Studio, I could only find compiler switches for C++ standards only. How can we tell visual…
user9411335
18
votes
5 answers

What do the different classifications of undefined behavior mean?

I was reading through the C11 standard. As per the C11 standard undefined behavior is classified into four different types. The parenthesized numbers refer to the subclause of the C Standard (C11) that identifies the undefined behavior. Example 1:…
user8753900