For faster navigation, this Iframe is preloading the Wikiwand page for C標準函式庫.

C標準函式庫

C 標準函式庫C standard library,缩写:libc)是在C語言程式設計中,所有符合標準的头文件header file)的集合,以及常用的函式庫實作程序(如 I/O 輸入輸出字串控制)。不像 COBOLFortranPL/I程式語言,在 C 語言的工作任務裡不會包含嵌入的關鍵字,所以幾乎所有的 C 語言程式都是由標準函式庫的函式來建立的。

設計

[编辑]

每一個函式的名稱與特性會被寫成一個電腦檔案,這個檔案就稱為標頭檔案,但是實際的函式實作是被分存到函式庫檔案裡。標頭檔的命名和領域是很常見的,但是函式庫的組織架構也會因為不同的編譯器而有所不同。標準函式庫通常會隨附在編譯器上。因為 C 編譯器常會提供一些額外的非 ANSI C 函式功能,所以某個隨附在特定編譯器上的標準函式庫,對其他不同的編譯器來說,是不相容的。

設計品質

[编辑]

大多数 C 標準函式庫設計得很好。有些少部分會為了商業優勢和利益,把某些舊函式視同錯誤或提出警告。字串輸入函式 gets()scanf() 讀取字串輸入的使用是很多緩衝區溢位的原因,大多数的程式設計指南會建議避免使用。另一個較為奇特的函式是 strtok(),它原本是作為早期的词法分析用途,但是它非常容易出錯(fragile),而且很難使用。

历史沿革

[编辑]

ANSI C共包括15個標頭檔。1995年,Normative Addendum 1NA1)批准了3个头文件(iso646.hwchar.hwctype.h)增加到C标准函数库中。C99标准增加了6个头文件(complex.hfenv.hinttypes.hstdbool.hstdint.htgmath.h)。C11标准中又新增了5个头文件(stdalign.hstdatomic.hstdnoreturn.hthreads.huchar.h)。至此,C标准函数库共有29个头文件:

名字 源自 描述
<assert.h> 包含断言,被用来在程序的调试版本中帮助检测逻辑错误以及其他类型的bug。
<complex.h> C99 一组操作复数的函数。
<ctype.h> 定义了一组函数,用来根据类型来给字符分类,或者进行大小写转换,而不关心所使用的字符集(通常是ASCII或其扩展字符集,也有EBCDIC)。
<errno.h> 用来测试由库函数报的错误代码。
<fenv.h> C99 定义了一组用来控制浮点数环境的函数。
<float.h> 定义了用于浮点数库特定实现的宏常量。
<inttypes.h> C99 定义精确的宽度整数类型。
<iso646.h> NA1 定义几个等效于C中某些运算符的宏。用于使用ISO 646变体字符集进行编程。
<limits.h> 定义了用于整数库特定实现属性的宏常量。
<locale.h> 定义C语言本地化函数。
<math.h> 定义C语言数学函数。
<setjmp.h> 定义了巨集setjmplongjmp,在非局部跳转的时候使用。
<signal.h> 定义C语言信号处理函数。
<stdalign.h> C11 用于查询和指定对象的数据结构对齐方式。
<stdarg.h> 用于查询和指定对象的数据结构对齐方式。
<stdatomic.h> C11 用于查询和指定对象的数据结构对齐方式。
<stdbool.h> C99 定义布尔数据类型。
<stddef.h> 定义了几个常见的类型与巨集
<stdint.h> C99 定义精确的宽度整数类型。
<stdio.h> 定义输入输出函数。
<stdlib.h> 定义数值转换函数,伪随机数生成函数,动态内存分配函数,过程控制函数。
<stdnoreturn.h> C11 用於指定非返回函數。
<string.h> 定义C语言字符串处理函数。
<tgmath.h> C99 定義類型通用數學函數。
<threads.h> C11 定義用於管理多個執行緒以及互斥體和條件變數的函數。
<time.h> 定義日期和時間處理函數。
<uchar.h> C11 用於操作Unicode字元的類型和函數。
<wchar.h> NA1 定義寬字串處理函數。
<wctype.h> NA1 定義一組函數,用於按類型對寬字元進行分類或在大小寫之間進行轉換。

参考文献

[编辑]

外部連結

[编辑]

参见

[编辑]
{{bottomLinkPreText}} {{bottomLinkText}}
C標準函式庫
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?