c99和c11的区别
difference between c99 and c11
我正在学习c,目前。 The book I read is C99 based. I want to update my knowledge to C11 after finishing this book, or change resource if there is a major difference. Thus, what I ask is for is an explanation or resource to update my knowledge. I only found this source。尽管如此,它似乎没有包含我需要的信息或不够简洁。
提前致谢。
P.S: 我想学习C11,因为我认为它是现在流行的标准。如果没有,请告诉我。
C11 标准的良好概述:
- https://en.wikipedia.org/wiki/C11_(C_standard_revision)
- http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
- https://smartbear.com/blog/test-and-monitor/c11-a-new-c-standard-aiming-at-safer-programming/
该标准包括对 C99 语言和库规范的多项更改,例如:
- 对齐规范(
_Alignas
说明符,_Alignof
运算符,aligned_alloc
函数,<stdalign.h>
header 文件)
_Noreturn
函数说明符和 <stdnoreturn.h>
header 文件
Type-generic 表达式使用 _Generic
关键字。例如,下面的宏 cbrt(x)
根据 x
的类型转换为 cbrtl(x)
、cbrt(x)
或 cbrtf(x)
:
#define cbrt(x) _Generic((x), long double: cbrtl, \
default: cbrt, \
float: cbrtf)(x)
Multi-threading支持(_Thread_local
storage-class说明符,<threads.h>
header包括线程creation/management函数,互斥,条件变量和 thread-specific 存储功能,以及 _Atomic
类型限定符和 <stdatomic.h>
用于不间断 object 访问)。
- 改进了基于 C Unicode 技术报告的 Unicode 支持 ISO/IEC TR 19769:2004(用于存储
UTF-16/UTF-32
编码数据的 char16_t
和 char32_t
类型,包括<uchar.h>
中的转换函数和相应的 u 和 U 字符串文字前缀,以及 UTF-8
编码文字的 u8 前缀)。
- 删除
gets
函数,在之前的 C 语言标准修订版 ISO/IEC 9899:1999/Cor.3:2007(E) 中弃用,支持新的安全备选方案,gets_s
.
- Bounds-checking 接口(附件 K)。
- 可分析性特征(附件 L)。
- 查询浮点类型特征的更多宏,涉及次正规浮点数和该类型能够存储的小数位数。
- 匿名结构和联合,在联合和结构嵌套时很有用,例如在
struct T { int tag; union { float x; int n; }; };
.
- 静态断言,在翻译过程中比
#if
和 #error
更晚的阶段评估,当翻译者理解类型时。
open
独有的 create-and-open 模式("…x"
后缀)。这与 POSIX
中的 O_CREAT|O_EXCL
类似,通常用于锁定文件。
quick_exit
函数作为终止程序的第三种方式,目的是在使用 exit
终止失败时至少进行最少的去初始化。
- 用于构造复数值的宏(部分原因是如果
imaginary
是无限的或 NaN
,real + imaginary*I
可能不会产生预期的值)。
根据 C 2011 standard 本身,以下是 C99 的主要变化:
Foreword
...
6 This third edition cancels and replaces the second edition, ISO/IEC 9899:1999, as
corrected by ISO/IEC 9899:1999/Cor 1:2001, ISO/IEC 9899:1999/Cor 2:2004, and
ISO/IEC 9899:1999/Cor 3:2007. Major changes from the previous edition include:
— conditional (optional) features (including some that were previously mandatory)
— support for multiple threads of execution including an improved memory sequencing
model, atomic objects, and thread-local storage (<stdatomic.h>
and
<threads.h>
)
— additional floating-point characteristic macros (<float.h>
)
— querying and specifying alignment of objects (<stdalign.h>
, <stdlib.h>
)
— Unicode characters and strings (<uchar.h>
) (originally specified in
ISO/IEC TR 19769:2004)
— type-generic expressions
— static assertions
— anonymous structures and unions
— no-return functions
— macros to create complex numbers (<complex.h>
)
— support for opening files for exclusive access
— removed the gets
function (<stdio.h>
)
— added the aligned_alloc
, at_quick_exit
, and quick_exit
functions
(<stdlib.h>
)
— (conditional) support for bounds-checking interfaces (originally specified in
ISO/IEC TR 24731−1:2007)
— (conditional) support for analyzability
我正在学习c,目前。 The book I read is C99 based. I want to update my knowledge to C11 after finishing this book, or change resource if there is a major difference. Thus, what I ask is for is an explanation or resource to update my knowledge. I only found this source。尽管如此,它似乎没有包含我需要的信息或不够简洁。
提前致谢。 P.S: 我想学习C11,因为我认为它是现在流行的标准。如果没有,请告诉我。
C11 标准的良好概述:
- https://en.wikipedia.org/wiki/C11_(C_standard_revision)
- http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1570.pdf
- https://smartbear.com/blog/test-and-monitor/c11-a-new-c-standard-aiming-at-safer-programming/
该标准包括对 C99 语言和库规范的多项更改,例如:
- 对齐规范(
_Alignas
说明符,_Alignof
运算符,aligned_alloc
函数,<stdalign.h>
header 文件) _Noreturn
函数说明符和<stdnoreturn.h>
header 文件Type-generic 表达式使用
_Generic
关键字。例如,下面的宏cbrt(x)
根据x
的类型转换为cbrtl(x)
、cbrt(x)
或cbrtf(x)
:#define cbrt(x) _Generic((x), long double: cbrtl, \ default: cbrt, \ float: cbrtf)(x)
Multi-threading支持(
_Thread_local
storage-class说明符,<threads.h>
header包括线程creation/management函数,互斥,条件变量和 thread-specific 存储功能,以及_Atomic
类型限定符和<stdatomic.h>
用于不间断 object 访问)。- 改进了基于 C Unicode 技术报告的 Unicode 支持 ISO/IEC TR 19769:2004(用于存储
UTF-16/UTF-32
编码数据的char16_t
和char32_t
类型,包括<uchar.h>
中的转换函数和相应的 u 和 U 字符串文字前缀,以及UTF-8
编码文字的 u8 前缀)。 - 删除
gets
函数,在之前的 C 语言标准修订版 ISO/IEC 9899:1999/Cor.3:2007(E) 中弃用,支持新的安全备选方案,gets_s
. - Bounds-checking 接口(附件 K)。
- 可分析性特征(附件 L)。
- 查询浮点类型特征的更多宏,涉及次正规浮点数和该类型能够存储的小数位数。
- 匿名结构和联合,在联合和结构嵌套时很有用,例如在
struct T { int tag; union { float x; int n; }; };
. - 静态断言,在翻译过程中比
#if
和#error
更晚的阶段评估,当翻译者理解类型时。 open
独有的 create-and-open 模式("…x"
后缀)。这与POSIX
中的O_CREAT|O_EXCL
类似,通常用于锁定文件。quick_exit
函数作为终止程序的第三种方式,目的是在使用exit
终止失败时至少进行最少的去初始化。- 用于构造复数值的宏(部分原因是如果
imaginary
是无限的或NaN
,real + imaginary*I
可能不会产生预期的值)。
根据 C 2011 standard 本身,以下是 C99 的主要变化:
Foreword
...
6 This third edition cancels and replaces the second edition, ISO/IEC 9899:1999, as corrected by ISO/IEC 9899:1999/Cor 1:2001, ISO/IEC 9899:1999/Cor 2:2004, and ISO/IEC 9899:1999/Cor 3:2007. Major changes from the previous edition include:
— conditional (optional) features (including some that were previously mandatory)
— support for multiple threads of execution including an improved memory sequencing model, atomic objects, and thread-local storage (<stdatomic.h>
and<threads.h>
)
— additional floating-point characteristic macros (<float.h>
)
— querying and specifying alignment of objects (<stdalign.h>
,<stdlib.h>
)
— Unicode characters and strings (<uchar.h>
) (originally specified in ISO/IEC TR 19769:2004)
— type-generic expressions
— static assertions
— anonymous structures and unions
— no-return functions
— macros to create complex numbers (<complex.h>
)
— support for opening files for exclusive access
— removed thegets
function (<stdio.h>
)
— added thealigned_alloc
,at_quick_exit
, andquick_exit
functions (<stdlib.h>
)
— (conditional) support for bounds-checking interfaces (originally specified in ISO/IEC TR 24731−1:2007)
— (conditional) support for analyzability