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

M_PI not available with gcc --std=c11 but with --std=gnu11?

I noticed M_PI is unavailable on c11. By looking at /usr/include/math.h I can see M_PI is defined if: #if !defined(__STRICT_ANSI__) || ((_XOPEN_SOURCE - 0) >= 500) ... #define M_PI 3.1415... #endif Moreover in the math.h from glibc…
nowox
  • 25,978
  • 39
  • 143
  • 293
14
votes
1 answer

How to use noreturn with function pointer?

I am writing a bootloader in C11. When the bootloader needs to transfer the control to the firmware, it reads a function pointer at a predefined memory address and calls it. The code looks like this: typedef void (FirmwareBootFn)(void); typedef…
MaxP
  • 2,664
  • 2
  • 15
  • 16
14
votes
3 answers

Why are typedef identifiers allowed to be declared multiple times?

From the C99 standard, 6.7(5): A declaration specifies the interpretation and attributes of a set of identifiers. A definition of an identifier is a declaration for that identifier that: for an object, causes storage to be reserved for that…
14
votes
4 answers

Sequence points and side effects: Quiet change in C11?

C99 §6.5 Expressions (1) An expression is a sequence of operators and operands that specifies computation of a value, or that designates an object or a function, or that generates side effects, or that performs a combination thereof. (2) Between…
mafso
  • 5,433
  • 2
  • 19
  • 40
13
votes
3 answers

Why can I use gets() in gcc -std=c11?

The gets() function has been removed from the C language. No such function exists in the standard. Yet I compile the following code: #include int main (void) { (void) gets (NULL); } using gcc -std=c11 -pedantic-errors -Wall…
Lundin
  • 195,001
  • 40
  • 254
  • 396
13
votes
1 answer

Is there a way to use GCC __attribute__((noreturn)) and sanely in a single translation unit?

In C11, there is the keyword _Noreturn which is a function specifier (like inline is) that indicates the function does not return — it calls exit() or equivalent. There is also a header, , the complete definition for which is: 7.23…
Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
13
votes
1 answer

Does realloc of memory allocated by C11 aligned_alloc keep the alignment?

Consider the following (C11) code: void *ptr = aligned_alloc(4096, 4096); ... // do something with 'ptr' ptr = realloc(ptr, 6000); Since the memory that ptr points to has a 4096-byte alignment from aligned_alloc, will it (read: is it guaranteed to)…
Drew McGowen
  • 11,471
  • 1
  • 31
  • 57
13
votes
2 answers

Using strdup in C11

I am able to compile the following using gcc version 4.7.2 #include int main(){ char text[] = "String duplicate"; char* dup = strdup(text); return 0; } But when I used the --std=c11 flag, I get the following…
Mike Fisher
  • 507
  • 6
  • 12
13
votes
2 answers

What is a composite type in C?

From §6.2.7.5 (page 66): EXAMPLE Given the following two file scope declarations: int f(int (*)(), double (*)[3]); int f(int (*)(char *), double (*)[]); The resulting composite type for the function is: int f(int (*)(char *), double…
Vorac
  • 8,726
  • 11
  • 58
  • 101
12
votes
4 answers

Behavior of "comma" operator in sizeof() operator In C

I wrote the code about sizeof operator. If I write something like: #include int main() { char a[20]; printf("%zu\n", sizeof(a)); return 0; } Output: 20 // Ok, it's fine But, If I use the comma operator like this: #include…
msc
  • 33,420
  • 29
  • 119
  • 214
12
votes
2 answers

Are noreturn attributes on exiting functions necessary?

Are noreturn attributes on never-returning functions necessary, or is this just an (arguably premature? -- at least for exits, I can't imagine why optimize there) optimization? It was explained to me that in a context such as void myexit(int s)…
Petr Skocik
  • 58,047
  • 6
  • 95
  • 142
12
votes
3 answers

Does comma separators in type definition in C guarantee the order?

Comma operators have the lowest precedence and left-to-right associativity, so this guarantees the order like: i = ++j, j = i++; i will be 2, and then j will be 1 after this statement if i and j are both 0 at first. However, does comma separators…
Kevin Dong
  • 5,001
  • 9
  • 29
  • 62
12
votes
3 answers

Assignment operator sequencing in C11 expressions

Introduction The C11 standard (ISO/IEC 9899:2011) has introduced a new definition of side effect sequencing within an expression (see related question). The sequence point concept has been complemented with sequenced before and sequenced after…
Krzysztof Abramowicz
  • 1,556
  • 1
  • 12
  • 30
12
votes
3 answers

C11 memory fence usage

Even for a simple 2-thread communication example, I have difficulty to express this in the C11 atomic and memory_fence style to obtain proper memory ordering: shared data: volatile int flag, bucket; producer thread: while (true) { int value =…
Jos v E
  • 165
  • 1
  • 5
12
votes
1 answer

Do unnamed bit-fields have well-defined semantics?

Is the following code guaranteed to terminate normally and successfully? #include struct foo_s { union { struct { unsigned a : 10; unsigned : 6; }; struct { unsigned :…
jxh
  • 69,070
  • 8
  • 110
  • 193