c11

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

送分小仙女□ 提交于 2019-12-04 17:17:38
问题 The gets() function has been removed from the C language. No such function exists in the standard. Yet I compile the following code: #include <stdio.h> int main (void) { (void) gets (NULL); } using gcc -std=c11 -pedantic-errors -Wall -Wextra and it compiles without giving any errors or warnings. Similarly, #include <stdio.h> int gets; int main (void) {} will not compile (error: 'gets' redeclared as different kind of symbol). In the standard 4. Conformance §6 we can read: A conforming

C1x: When will it land, what to expect?

淺唱寂寞╮ 提交于 2019-12-04 16:24:02
问题 C99 still isn't supported by many compilers, and much of the focus is now on C++, and its upcoming standard C++1x. I'm curious as to what C will "get" in its next standard, when it will get it, and how it will keep C competitive. C and C++ are known to feed on one another's improvements, will C be feeding on the C++1x standard? What can I look forward to in C's future? 回答1: The ISO/IEC 9899:2011 standard, aka C11, was published in December 2011. The latest draft is N1570; I'm not aware of any

Do I need -pedantic flag from GCC with C11?

断了今生、忘了曾经 提交于 2019-12-04 13:21:26
问题 I'm currently running Linux Mint on my Machine with GCC-5.3 because C11 is included default. I started learning C for myself just for fun and at that time the GCC version was 4.8 if I remember right. Any way if one use GCC-4.8 with -pedantic flag on the following program: #include <stdio.h> #include <string.h> int main(void){ char *arr =

Does C99/C11 restrict type qualifier imply anything for functions without definition?

孤人 提交于 2019-12-04 10:25:10
Suppose we have a function declaration for which we do not have access to its definition: void f(int * restrict p, int * restrict q, int * restrict r); Since we do not know how the pointers will be accessed, we cannot know if a call will trigger undefined behavior or not -- even if we are passing the same pointer, like the example at 6.7.3.1.10 explains: The function parameter declarations: void h(int n, int * restrict p, int * restrict q, int * restrict r) { int i; for (i = 0; i < n; i++) p[i] = q[i] + r[i]; } illustrate how an unmodified object can be aliased through two restricted pointers.

C11 Standard docs

时光总嘲笑我的痴心妄想 提交于 2019-12-04 08:16:57
问题 Starting from this SO protected question I'm trying to understand what the difference between those documents: 9899 2012 costs $60 9899 2011 costs $265 As you can see those documents have very different prices and I don't know if the cheaper one is valid or is something like draft or cut copy of the real standard. Did someone buy the INCITS one? EDIT As @Chqrlie pointed out: What is the difference between the ANSI and ISO official documents available for a free and the final draft freely

What is the correct definition of size_t? [duplicate]

和自甴很熟 提交于 2019-12-04 07:41:39
This question already has answers here : What is size_t in C? (12 answers) Closed 4 years ago . First of all, what do I mean, by 'correct definition`? For example, K&R in "C Programming Language" 2nd ed. , in section 2.2 Data Types and Sizes , make very clear statements about integers: There are short , int and long for integer types. They are needed to repesent values of different boundaries. int is a "naturally" sized number for a specific hardware, so also probably the most fastest. Sizes for integer types short , int and long are purely implementation-dependent. But they have restrictions.

C11 _Generic usage

半城伤御伤魂 提交于 2019-12-04 06:11:29
I was trying to learn how to use the "new" C11 Generic expressions but I ran into a wall. Consider the following code: #include <stdlib.h> #include <stdio.h> #define test(X, Y, c) \ _Generic((X), \ double: _Generic((Y), \ double * : test_double, \ default: test_double \ ), \ int: _Generic((Y), \ int * : test_int, \ default: test_int \ ) \ ) (X, Y, c) int test_double(double a, double *b, int c); int test_int(int a, int *b, int c); int test_double(double a, double *b, int c) { return 1; } int test_int(int a, int *b, int c) { return 2; } int main() { double *t = malloc(sizeof(double)); int *s =

Why are structs not allowed in equality expressions in C? [duplicate]

一笑奈何 提交于 2019-12-04 06:02:09
This question already has answers here : Closed 2 years ago . Why doesn't C provide struct comparison? (5 answers) The unavailability of structs as comparison operands is one of the more obvious things in C that don't make too much sense (to me). structs can be passed by value and copied via assignments but == is not specified for them. Below are the relevant parts of the C11 standard (draft) that define the constraints of the equality operators ( == and != ) and the simple assignment operator ( = ). Note the lack of structures and unions in the constraints of equality operators. (Apart from

Visual Studio 2017 does not supportC11 new feature _Generic

做~自己de王妃 提交于 2019-12-04 04:39:36
问题 Can anybody advise why Visual Studio 2017 does not support the C11 new feature _Generic ? I found it is a very useful feature but cannot used in Visual Studio 2017. Below is the sample code: #include <stdio.h> #define MYTYPE(X) _Generic((X),\ int:"int",\ float:"float",\ double:"double",\ default:"other") int main(void) { int d = 5; printf("%s\n", MYTYPE(d)); printf("%s\n", MYTYPE(2.0*D)); return 0; } The complier will give below warnings and errors: 1>------ Build started: Project: Project1,

A bug in GCC implementation of bit-fields

隐身守侯 提交于 2019-12-04 03:02:45
Working in C11, the following struct: struct S { unsigned a : 4; _Bool b : 1; }; Gets layed out by GCC as an unsigned (4 bytes) of which 4 bits are used, followed by a _Bool (4 bytes) of which 1 bit is used, for a total size of 8 bytes. Note that C99 and C11 specifically permit _Bool as a bit-field member. The C11 standard (and probably C99 too) also states under §6.7.2.1 'Structure and union specifiers' ¶11 that: An implementation may allocate any addressable storage unit large enough to hold a bit-field. If enough space remains, a bit-field that immediately follows another bit-field in a