C语言新标准C11
2013-12-12 10:59
603 查看
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()。
相比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()。
相关文章推荐
- C11标准委员会成员解读C语言新标准
- C语言新标准C11
- C语言的C11 标准有哪些改进的地方?C11 为何不如 C++11 流行?
- ISO发布新的C语言——新标准C11
- C11标准委员会成员解读C语言新标准
- C语言最新标准C11问世——ISO updates C standard
- c语言之标准(K&RC 、c89、c99、c11)
- 标准C语言第六天
- C语言标准输出函数 printf()
- 【C语言】从标准输入读取字符,并把它们写到标准输出,除了 大写字母转换成小写字母之外,其他的原样输出。
- c++基于c11的新特性以及与c99版本C语言的区别
- 【C/C++】标准C语言头文件
- MISRA工业标准C语言编程规范
- 使用标准C语言建立动态随机数组
- 标准C语言,不用引入新变量就可以交换两个变量的方法及其注意事项
- C语言如何使标准输出重定向到一个文件
- C语言标准
- 日期与时间 - C语言标准链接库函数小结
- 关于标准C语言的预定义宏【转】
- c语言标准库中字符转换函数和数字转换函数