c11

Is support of Annex K in C11 required for a conforming implementation?

試著忘記壹切 提交于 2019-11-27 06:07:11
问题 While answering a question that made use of some functions ( sscanf_s and sprintf_s ) that I thought were not standard C, Daniel Fischer brought to my attention that the functions in question were defined in Annex K. I understand generally that normative means it helps define the standard. But, an annex to the C Standard has traditionally been treated as informative only. Annex K is labeled as normative in the C11 Standard. It defines "safe" functions. Does this mean a compiler that doesn't

What does “representable” mean in C11?

為{幸葍}努か 提交于 2019-11-27 04:47:09
问题 According to C11 WG14 draft version N1570: The header <ctype.h> declares several functions useful for classifying and mapping characters. In all cases the argument is an int , the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF . If the argument has any other value, the behavior is undefined. Is it undefined behaviour?: #include <ctype.h> #include <limits.h> #include <stdlib.h> int main(void) { char c = CHAR_MIN; /* let assume that char is

C11 <thread.h> in GCC?

孤者浪人 提交于 2019-11-27 04:04:32
问题 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 thread.h not included in the GCC distribution yet? 回答1: The standard C11 header for threading is <threads.h> , not <thread.h> . See section 7.26 of the N1570 draft. Most of the C standard library, including stdio for example, is not included in the

Does any C library implement C11 threads for GNU/Linux?

不问归期 提交于 2019-11-27 03:47:33
There have been a lot of questions about C11 and C11 threading, but I don't see a definitive answer anywhere: Does any C library implement the C11 threading interface usable on GNU/Linux-like? e.g., provide the "optional" <threads.h> and the thread support library like thrd_create() , from the C11 standard near p. 376. Ideally, I'd like to find a library that is common-ish, open-source or free, for common/generic/multi architecture (e.g., GNU/Linux, x86_64, or portable-ish). A few of the more helpful and relevant SO links: this one and this one on glibc ; this one that's talking about the

Header for scanf_s function

陌路散爱 提交于 2019-11-27 03:41:21
问题 While answering this question I compiled the code on Ideone and got this error implicit declaration of function ‘scanf_s’ [-Wimplicit-function-declaration] Isn't stdio.h is the header for scanf_s ? 回答1: scanf_s is Microsoft-specific. Header is stdio.h but not in GCC. Used to Read formatted data from the standard input stream. These versions of scanf, scanf_s, _scanf_l, wscanf, _wscanf_l have security enhancements Where as Ideone uses GCC because of this only you got undefined reference to

Why are typedef identifiers allowed to be declared multiple times?

故事扮演 提交于 2019-11-27 02:43:44
问题 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 object; for a function, includes the function body; for an enumeration constant or typedef name, is the (only) declaration of the identifier. If identifiers with typedef are in fact definitions, then why are they allowed to be declared more than once?

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

穿精又带淫゛_ 提交于 2019-11-27 02:34:27
问题 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? // VLA in the middle of some struct, between other fields int b; } args; args.b=0; for(args.a=0;args.a<argc;args.a++) { args.params[args.a]=argv[0][0]; args.b++; } return args.b; } This code compiled without warnings: $ gcc-4.6 -Wall -std=c99 a.c && echo $? 0 $ ./a.out ; echo $? 1 $ ./a.out

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

依然范特西╮ 提交于 2019-11-27 02:11:35
问题 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 can change the parameter names, replace int by a typedef name defined as int , or write char *argv[] as char **argv ). It may also be defined "in some other implementation-defined manner" -- which means that things like int main(int argc, char *argv[]

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

≡放荡痞女 提交于 2019-11-27 00:36:58
问题 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 statically typed arrays from variable-length arrays? Or are they just syntactic sugar? 回答1: static in parameter array declarator void f(int a[static 10]); static here is an indication that parameter a is a pointer to int but that the array objet

Incompatible pointer types passing in _Generic macro

不打扰是莪最后的温柔 提交于 2019-11-26 22:58:32
The following code generates 2 warnings which are described in the question's title. #include <stdio.h> 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) _Generic((num), \ int* : _print_i(num), \ float* : _print_f(num)) int main(void) { print((&(int){10})); print((&(float){10.f})); return 0; } OUTPUT: int : 10 float : 10.000000 I know, this macro could be written like the following: #define print(num) _Generic((num), \ int* : _print_i, \ float* : _print_f)(num) and in that case, there won't be any warnings,