C Standard: C90, C99, C11_C / C ++

 

The original C language is no uniform standard, the first standard is about 90 to determine the content than some previous improvements:

   1, an increase of real standard library;

   2, the new and characteristic pre-command;

   3, the function prototype function allows the declaration;

   4, specify the parameters of some types of new keywords, including const, volatile and signed;

   5, wide characters wide and multi-byte character string;

   6, many small changes and clarification of the rules of engagement, declarations and type checking;

99 years later to have a new amendment:

   1, increasing restrictions on the compiler, such as source code to support each row requires at least 4095 bytes, variable names required to support the function name 63 bytes (extern supported to claim 31);

   2, to enhance the preprocessing functions. For example: take the variable macro support parameters #define Macro (...) __VA_ARGS__;

                                                         When using macros, allowing parameter is omitted, the omitted parameter expand to the empty string;

                                                         Support for single-line comments begin with // (This feature is in fact in many of the C89 compiler already supported);

    3, adding new keyword restrict, inline, _Complex, _Imaginary, _Bool; support for long long, long double _Complex, float _Complex and other types;

    4, support an array of variable length, i.e. the length of the array can be determined at run time, such as an array using the variable length. Use forms int a [var] the declaration. However, taking into account the efficiency and implementation, variable length arrays can not be used globally, or struct with a union in.
    5, the variable is not necessary at the beginning of a block of statements reputation ,, for the promotion written statement for (int i = 0; i <100; ++ i) a form that is valid only within i for block.

    6, allowing the use of (type_name) {xx, xx, xx} constructor forms a structure similar to C ++ anonymous structure.

    7, initialization structure allows the assignment of specific elements in the form of:

                      struct test{int a[3],b;} foo[] = { [0].a = {1}, [1].a = 2 }

                     struct test {int a, b, c, d;} foo = {.a = 1, .c = 3,4, .b = 5}; // 3,4 is .c, .d assignment

     8, format string, use \ u support of unicode characters.

     9, to support the description of the floating point hexadecimal; printf scanf format string adds support for type long long int; internal floating-point data is described supports a new standard may be specified using #pragma compiler directive.

     10, in addition to the existing __line__ __file__, an increase of __func__ get the current function name.

     11, allows the compiler to simplify expressions are numbers; canceled the function return type defaults to int provisions.

     12, the modified definition at negative /% process, which can give a clear result, for example in the C89 -22 / 7 = -3, -22% 7 = -1, can be -22 / 7 = 4, - 22% 7 = 6. And clearly C99 -22 / 7 = -3, -22% 7 = -1, only one result.

     13, allows an array of struct definition does not specify its final length, written as [] (flexible array member).

  14, const const int i to be processed as const int i; for wide character input and output and a long integer, and so do the corresponding support.

     15, a number of additions and modifications to the standard header files, such as the definition of bool <stdbool.h>, define a standard length int <inttypes.h>, define a plurality of <complex.h>, defined wide characters <wctype. h>, similar to the generic mathematical functions <tgmath.h>, floating point related <fenv.h>. In <stdarg.h> increased va_copy parameters for copying ... of. Has increased by struct tmx, the expansion of the struct tm do.


In 11 years, when ISO released a new standard in the new C language C11:

     1, the alignment process (the Alignment) standardized (including _Alignas identifier, Alignof operator, aligned_alloc function and <stdalign.h> header.

     2, _Noreturn marker function, similar to the gcc __attribute __ ((noreturn)).

     3, _Generic keywords.

     4, multi-threaded (Multithreading) support, including:

                  _Thread_local storage type identifier, <threads.h> header file, which contains the functions for creating and managing threads.

                 _Atomic type modifiers and <stdatomic.h> header.

      5, enhanced Unicode support. Based on C Unicode Technical Report ISO / IEC TR 19769: 2004, improved support for Unicode. Including increased char16_t char32_t data type and UTF-16 / UTF-32 encoded, a header file containing unicode string conversion function <uchar.h>.

      6, delete the gets () function, using a new, more secure function gets_s () instead.

      7、增加了边界检查函数接口,定义了新的安全的函数,例如 fopen_s(),strcat_s()

      8、匿名结构体/联合体支持。这个在gcc早已存在,C11将其引入标准。

      9、静态断言(Static assertions),_Static_assert(),在解释 #if 和 #error 之后被处理。

      10、新的 fopen() 模式,(“…x”)。类似 POSIX 中的 O_CREAT|O_EXCL,在文件锁中比较常用。

      11、新增 quick_exit() 函数作为第三种终止程序的方式。当 exit()失败时可以做最少的清理工作。

C90和C99容易弄混,这也是现在用的最多的两个版本,至于C11的话基本没见人用,反正有了也总结一下 。

=================================================================================

C99标准现在还有些编译器支持的不太好,但是用gcc已经完全没问题了。

C99重要的更新如下:
指定初始化(Designated Initializers)

允许对数组元素或结构体元素的特定成员进行初始化而不用按顺序进行初始化。 主要是结构体成员的指定,和数组成员的指定。
结构体成员,比如,

 
struct S {
  int a; int b; }; struct S instance1={ .a=1, }; struct S array1[5]={ [1].a = 3, [1].b = 5, { // array1[2] = {7, 11} .a = 7, .b = 11 } // array1[4] = {13, 17} [4] = { .a = 13, .b = 17 } }; 
变长数组(Variable Length Arrays)

C99支持动态长度的数组(VLA),也就是数组在栈上由运行时分配。退出作用域时,数组使用的空间被释放。所以VLA不能在全局定义,或者有extern,static修饰符。

 
int n;              //define a variable n
int array[n]; //define an array with length n 
伸缩型数组成员(Flexible Array Members)

C99支持伸缩数组成员,最后一个结构体成员的大小可以在运行时分配。

 
struct flex_array  
{  
       int a; double b; char c[]; }; struct flex_array *fa_sample = (struct flex_array*)malloc(sizeof(flex_array)+100*sizeof(char)); fa_sample->c[2] = 's'; 
bool类型

用<stdbool.h>来使用bool类型,而使用true或者false来为变量赋值或比较。

long long类型

新的long long类型为了统一不同编译器实现对64位的支持,在format时使用%lld来输出long long。

inline函数

尽量使用inline函数来替代所谓的“函数宏”。

混合声明(mix declarations and code)

现在可以在代码里随处定义变量了。但是要注意作用域。

// 行注释

不解释,编译器早就支持了。

for循环变量初始化(for loop intializers)

在for语句里可以定义局部变量了,早就该有的特性。

变参宏(Variadic Macros)

gcc的编译器很早之前就支持这个特性了,微软的编译器之前是不可以这个用的。最新的版本不确定。

 
#define debug(fmt, ...)                    \
        printf("[DEBUG] %s:%d <%s>: " fmt, \
               __FILE__, __LINE__, __func__, ##__VA_ARGS__)
复合常量(Compound Literals)
复数(Complex Numbers)

用<complex.h>来使用complex类型

restrict指针
reference

https://blog.csdn.net/syrchina/article/details/6662243

C11 新特性

C11的主要新特性是增加了<thread.h>,还有thread_local修饰符表示变量只在本线程可用。另外相比<pthread.h>,调用格式完全类似,只是函数名前缀缩短了一下,现在是thrd_,mtx_, cnd_和tss_作为前缀。

Guess you like

Origin www.cnblogs.com/CodeWorkerLiMing/p/12348507.html