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
-1
votes
0 answers

error: ‘strncpy_s’ was not declared in this scope

#define __STDC_WANT_LIB_EXT1__ 1 #define __STDC_LIB_EXT1__ 1 #include #include #include #include int main() { // Write C code here printf("Hello world"); char* key=""; char* key1=""; char…
Ek1234
  • 407
  • 3
  • 7
  • 17
-1
votes
1 answer

Initializing struct in function call parameter

I have code like this: typedef enum { API_SIG_SERVER_CONNECTED = 1, API_SIG_DATA_RECEIVED, } api_signals_t; typedef struct { api_signals_t signal; void * params; } api_msg_t; static void send_msg_to_api(api_msg_t * p_msg){ //…
Kamil
  • 13,363
  • 24
  • 88
  • 183
-1
votes
1 answer

Why exactly can't function pointers be implicitly converted?

Rationale for C, Revision 5.10, April-2003: It is invalid to convert a pointer to a function of one type to a pointer to a function of a different type without a cast. It seems that they wanted to say "without an explicit cast". Question: Why…
pmor
  • 5,392
  • 4
  • 17
  • 36
-1
votes
2 answers

Should compilation of previously non-preprocessed source code lead to the same diagnostics as compilation of previously preprocessed source code?

Consider this scenario: $ cat t783.c #define EXPR ("xxx" + 1) char* s = EXPR; $ clang t783.c -c t783.c:2:11: warning: adding 'int' to a string does not append to the string [-Wstring-plus-int] $ clang t783.c -E | clang -xc - -c t783.c:2:18:…
pmor
  • 5,392
  • 4
  • 17
  • 36
-1
votes
1 answer

How to automatically select between %f and %a w/o losing precision?

Sample code: void print_f( float f ) { ... } int main( void ) { print_f( 1.0f ); // prints 1.0 print_f( 29.0f ); // prints 29.0 print_f( 29.13f ); // prints 0x1.d2147ap+4 print_f( 256.0f ); // prints 256.0 …
pmor
  • 5,392
  • 4
  • 17
  • 36
-1
votes
3 answers

Is there a standard way to prohibit reading (via assignment) of a variable?

It is known and useful features that: const type qualifier prohibits writing (modification) of a variable register storage-class specifier prohibits taking address of a variable However, is there a standard way to prohibit reading (via assignment)…
pmor
  • 5,392
  • 4
  • 17
  • 36
-1
votes
2 answers

Shall a #pragma leading to nonstandard behavior cause __STDC__ macro not to be defined to 1?

Simple question: shall a #pragma leading to nonstandard behavior cause __STDC__ macro not to be defined to 1? (Does the C standard explicitly prescribes that? If yes, then in which section? If no, then why?) Reason of the question: see below. Sample…
pmor
  • 5,392
  • 4
  • 17
  • 36
-1
votes
1 answer

QNAN passed into C standard library functions (ex. llrintf): not clear whether FP exceptions are raised or not

The macro NAN from math.h is quiet NAN: ISO/IEC 9899:2011 (E) (emphasis added): The macro NAN is defined if and only if the implementation supports quiet NaNs for the float type. It expands to a constant expression of type float representing a…
pmor
  • 5,392
  • 4
  • 17
  • 36
-1
votes
2 answers

C preprocessor: does this code lead to well-defined behavior?

Does this code lead to well-defined behavior? If no, then which rules / statements of C standard are violated? How exactly they are violated? Code #1: #define B(a1, ...) a1 int main ( void ) { return B(0); } Code #2: #define M1(...) …
pmor
  • 5,392
  • 4
  • 17
  • 36
-1
votes
2 answers

Text editor with multipe undo/redo in c

I'm starting a school project: we have to code an efficient text editor in c. To command this i can use: (row1,row2)c (row1,row2)d (row1,row2)p (number)u (number)r These commands are used to change text between row1 and row2 (the c), delete text…
-1
votes
1 answer

Is casting incomplete struct pointers undefined behavior?

I was currently reading about some strict aliasing rules, and I was wondering whether casting a pointer to an incomplete struct is undefined behavior. Example 1: #include struct abc; int main(int argc, char *argv[]) { struct abc…
Julius
  • 1,155
  • 9
  • 19
-1
votes
1 answer

printf() function in loop #3 gives unexpected result

There are 3 loops, which last loop does not behave as expected. Loop #2 and loop #3 are bad code styling. They are here just for demonstration. Question is why printf() in loop #3 gives unexpected output and printf() in loop#2 gives expected…
Zeljko M
  • 1
  • 2
-1
votes
1 answer

bsearch() on an array of strings in C

I am implementing a code in C so as to copy a string in an array of characters ( string ) and then later do a bsearch on it. But unexpectedly the bsearch returns false for results that should be true. I am guessing it has something to do with how i…
Nirmik
  • 87
  • 3
  • 15
-1
votes
1 answer

I can not pass by reference my node

I dont want create general *head node and I want to pass by reference and chance my data but although create new node for next node I cant reach my new node on main. İf I look n1.next in main I see it is null.Why ?What is wrong ? #include…
reddawn
  • 11
  • 6
-1
votes
1 answer

Generic sum macro and nested macro expansion

I wrote a generic sum macro using the C11 _Generic keyword, but I'm having problems expanding the macro inside other generic function definitions. Here is the sum macro with all the helper macros: // Helper macros #define _num_map($, _) $(char)_…
A_User
  • 397
  • 1
  • 9