C语言新标准C11

2011年12月8号,ISO 发布了新的 C 语言的新标准——C11,之前被称为C1X,官方名称 ISO/IEC 9899:2011。
 
相比C99的变化
1. 对齐处理操作符 alignof,函数 aligned_alloc(),以及 头文件 <stdalign.h>。见 7.15 节。
2. _Noreturn 函数标记,类似于 gcc 的 __attribute__((noreturn))。例子:
_Noreturn void thrd_exit(int res);
3. _Generic 关键词,有点儿类似于 gcc 的 typeof。例子:
#define cbrt(X) _Generic((X), long double: cbrtl, \
default: cbrt, \
float: cbrtf)(X)
4. 静态断言( static assertions),_Static_assert(),在解释 #if 和 #error 之后被处理。例子:
_Static_assert(FOO > 0, "FOO has a wrong value");
5. 删除了 gets() 函数,C99中已经将此函数被标记为过时,推荐新的替代函数 gets_s()。
6. 新的 fopen() 模式,(“…x”)。类似 POSIX 中的 O_CREAT|O_EXCL,在文件锁中比较常用。
7. 匿名结构体/联合体,这个早已经在 gcc 中了,我们并不陌生,定义在 6.7.2.1 p13。
8. 多线程支持,包括:_Thread_local,头文件 <threads.h>,里面包含线程的创建和管理函数(比如 thrd_create(),thrd_exit()),mutex (比如 mtx_lock(),mtx_unlock())等等,更多内容清参考 7.26 节。
9. _Atomic类型修饰符和 头文件 <stdatomic.h>,见 7.17 节。
10. 带边界检查(Bounds-checking)的函数接口,定义了新的安全的函数,例如 fopen_s(),strcat_s() 等等。更多参考 Annex K。
11. 改进的 Unicode 支持,新的头文件 <uchar.h> 等。
12. 新增 quick_exit() 函数,作为第三种终止程序的方式,当 exit() 失败时可以做最少的清理工作(deinitializition),具体见 7.22.4.7。
13. 创建复数的宏, CMPLX(),见 7.3.9.3。
14. 更多浮点数处理的宏 (More macros for querying the characteristics of floating point types, concerning subnormal floating point numbers and the number of decimal digits the type is able to store)。
15. struct timespec 成为 time.h 的一部分,以及宏 TIME_UTC,函数 timespec_get()。

猜你喜欢

转载自blog.csdn.net/braveyly/article/details/17279261
C11