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
27
votes
5 answers

Generics for multiparameter C functions in C11

I understand C11 generics for one-parameter functions, like this: (from here) #define acos(X) _Generic((X), \ long double complex: cacosl, \ double complex: cacos, \ float complex: cacosf, \ long double: acosl, \ float: acosf, \ …
Mathuin
  • 790
  • 1
  • 6
  • 13
26
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
  • 254,901
  • 44
  • 429
  • 631
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
  • 60,350
  • 16
  • 207
  • 386
25
votes
2 answers

Side effects in generic expressions

I'm doing some experiments with the new _Generic keyword and stumbled upon a special case regarding multiple evaluations. See the following: #include #define write_char(c) _Generic(c, char: putchar, const char: putchar)(c) int…
michaelmeyer
  • 7,985
  • 7
  • 30
  • 36
25
votes
3 answers

C11 _Generic: how to deal with string literals?

Using the _Generic feature in C11, how do you deal with string literals? For instance: #include #define foo(x) _Generic((x), char *: puts(x)) int main() { foo("Hello, world!"); return 0; } gives this error on clang: controlling…
Michael Rawson
  • 1,905
  • 1
  • 15
  • 25
24
votes
1 answer

__STDC_LIB_EXT1__ availability in gcc and clang

Since a quick Google search did not find anything, I will try to ask here (since many people involved in gcc/clang hang around here) - What is the status of __STDC_LIB_EXT1__ in gcc/clang? We are developing a cross platform applicataion and I wanted…
Rudolfs Bundulis
  • 11,636
  • 6
  • 33
  • 71
24
votes
4 answers

Is there a meaningful distinction between freestanding and hosted implementations?

The question I have is mostly related to section four, paragraph six. The two forms of conforming implementation are hosted and freestanding. A conforming hosted implementation shall accept any strictly conforming program. As I understand, this…
autistic
  • 1
  • 3
  • 35
  • 80
24
votes
3 answers

What ABI, if any, restricts the size of [u]intmax_t?

Starting with the 1999 edition, the ISO C standard defines a standard header which defines, among other things, the typedefs intmax_t and uintmax_t. These designate, respectively, "a (signed|unsigned) integer type capable of representing…
Keith Thompson
  • 254,901
  • 44
  • 429
  • 631
24
votes
3 answers

Variable length array in the middle of struct - why this C code is valid for gcc

There is some strange code using VLA (Variable Length Arrays) which is treated as Valid C (C99, C11) by gcc 4.6: $ cat a.c int main(int argc,char**argv) { struct args_t{ int a; int params[argc]; // << Wat? …
osgx
  • 90,338
  • 53
  • 357
  • 513
23
votes
1 answer

Why didn't gcc (or glibc) implement _s functions?

_s functions, such as scanf_s, printf_s seems to be optional standard. MSVC has implemented these functions, but gcc hasn't. Is there specific reason for not implementing secure functions? Is scanf of glibc secure enough?
suhdonghwi
  • 955
  • 1
  • 7
  • 20
23
votes
1 answer

in GCC 4.8?

I'd like to make use of the new atomic operations provided by the C11 standard. However, trying to #include the appropriate header file gives me this: csort-par.c:5:23: fatal error: stdatomic.h: No such file or directory #include…
Patrick Collins
  • 10,306
  • 5
  • 30
  • 69
22
votes
1 answer

C11 type-generic expressions - why not just add function overloading?

I was just reading the Wikipedia article on C11, the new version of the C standard released in Dec 2011, and I saw that one of the added features was "type-generic expressions": Type-generic expressions using the _Generic keyword. For example, the …
HighCommander4
  • 50,428
  • 24
  • 122
  • 194
22
votes
1 answer

C11 alignas vs. clang -Wcast-align

So I have the following minimized C11 code that defines a struct containing a uint16_t (which means the struct it should be aligned to 2 bytes) and I want to cast a char buffer to a pointer to that struct. With warnings turned all up, clang rightly…
handschuhfach
  • 388
  • 2
  • 8
22
votes
2 answers

Incompatible pointer types passing in _Generic macro

The following code generates 2 warnings which are described in the question's title. #include static void _print_f(float *f){printf("float : %f\n", *f);} static void _print_i(int *i) {printf("int : %d\n", *i);} #define print(num)…
Peter Varo
  • 11,726
  • 7
  • 55
  • 77
22
votes
1 answer

why is there no aligned calloc in C11

The C11 standard added the aligned_alloc function to allocate uninitialized aligned memory. The standard also includes the calloc function to allocate memory which is initialized to zero but only aligns it to the size of the largest type. Why does…
jtaylor
  • 2,389
  • 19
  • 19
1 2
3
58 59