c99標準和c11有什麼區別

來源:魅力女性吧 1.64W
c99標準和c11有什麼區別

C11相比C99的變化

1、對齊處理操作符 alignof,函數 aligned_alloc(),以及 頭文件 <stdalign.h>。

2、 _Noreturn 函數標記,類似於  gcc 的 __attribute__((noreturn))。

3、_Generic 關鍵詞,有點兒類似於 gcc 的 typeof。

4、靜態斷言( static assertions),_Static_assert(),在解釋 #if 和 #error 之後被處理。

5、 刪除了 gets() 函數,C99中已經將此函數被標記為過時,推薦新的替代函數 gets_s()。

6、 新的 fopen() 模式,(“…x”)。類似 POSIX 中的 O_CREAT|O_EXCL,在文件鎖中比較常用。

7、 匿名結構體/聯合體,這個早已經在 gcc 中了,我們並不陌生,定義在 p13。

8、 多線程支持,包括:_Thread_local,頭文件 <threads.h>,裏面包含線程的創建和管理函數(比如 thrd_create(),thrd_exit()),mutex 等等。

9、 _Atomic類型修飾符和 頭文件 <stdatomic.h>。

10、 帶邊界檢查(Bounds-checking)的函數接口,定義了新的安全的函數。更多參考 Annex K。

11、 改進的  Unicode 支持,新的頭文件 <uchar.h> 等。

12、 新增 quick_exit() 函數,作為第三種終止程序的方式,當 exit() 失敗時可以做最少的清理工作(deinitializition)。

13、 創建複數的宏, CMPLX()。

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()。

熱門標籤