C标准函数库

本文详细介绍了C语言标准函数库的组成、设计品质、历史沿革以及包含的头文件,涵盖了从C语言基础到现代C语言标准的演变。

C语言程序设计里,C 标准函数库C Standard library)收集所有目前符合标准的头文件head file),以及常用的函数库实现程序,例如 I/O 输入输出字符串控制。不像 COBOLFortranPL/I等编程语言,在 C 语言的工作任务里不会包含嵌入的关键字,所以几乎所有的 C 语言程序都是由标准函数库的函数来创建的。

目录

设计

每一个函数的名称与特性会被写成一个电脑文件,这个文件就称为头文件,但是实际的函数实现是被分存到函数库文件里。头文件的命名和领域是很常见的,但是函数库的组织架构也会因为不同的编译器而有所不同。标准函数库通常会随附在编译器上。因为 C 编译器常会提供一些额外的非 ANSI C 函数功能,所以某个随附在特定编译器上的标准函数库,对其他不同的编译器来说,是不兼容的。

设计品质

大多 C 标准函数库在设计上做得相当不错。有些少部分的,会为了商业优势和利益,会把某些旧函数视同错误或提出警告。字符串输入函数 gets()(以及 scanf() 读取字符串输入的使用上)是很多缓存溢出的原因,而且大多的程序设计指南会建议避免使用它。另一个较为奇特的函数是 strtok(),它原本是作为早期的词汇分析用途,但是它非常容易出错(fragile),而且很难使用。

历史沿革

1995年,Normative Addendum 1 (NA1)批准了三个头文件(iso646.h, wchar.h, and wctype.h)增加到C标准函数库中。C99标准增加了六个头文件(complex.h, fenv.h, inttypes.h, stdbool.h, stdint.h, and tgmath.h)。C11标准中又新增了5个头文件(stdalign.h, stdatomic.h, stdnoreturn.h, threads.h, and uchar.h)。至此,C标准函数库共29个头文件:


名字源自描述
<assert.h> Contains the assert macro, used to assist with detecting logical errors and other types of bug in debugging versions of a program.
<complex.h>C99A set of functions for manipulating 复数.
<ctype.h> Defines set of functions used to classify characters by their types or to convert between upper and lower case in a way that is independent of the used character set (typically ASCII or one of its extensions, although implementations utilizing EBCDIC are also known).
<errno.h> For testing error codes reported by library functions.
<fenv.h>C99Defines a set of functions for controlling 浮点数 environment.
<float.h> Defines macro constants specifying the implementation-specific properties of the 浮点数 library.
<inttypes.h>C99Defines exact width integer types.
<iso646.h>NA1Defines several macros that are equivalent to some of the operators in C. For programming in ISO 646 variant character sets.
<limits.h> Defines macro constants specifying the implementation-specific properties of the integer types.
<locale.h> Defines C localization functions.
<math.h> Defines C mathematical functions.
<setjmp.h> Declares the macros setjmp and longjmp, which are used for non-local exits.
<signal.h> Defines C signal handling functions.
<stdalign.h>C11For querying and specifying the data structure alignment of objects.
<stdarg.h> For accessing a varying number of arguments passed to functions.
<stdatomic.h>C11For atomic operations on data shared between threads.
<stdbool.h>C99Defines a boolean data type.
<stddef.h> Defines several useful types and macros.
<stdint.h>C99Defines exact width integer types.
<stdio.h> Defines core input and output functions
<stdlib.h> Defines numeric conversion functions, pseudo-random numbers generation functions, dynamicmemory allocation, process control functions
<stdnoreturn.h>C11For specifying non-returning functions.
<string.h> Defines C string handling functions.
<tgmath.h>C99Defines type-generic mathematical functions.
<threads.h>C11Defines functions for managing multiple threads as well as mutexes and condition variables.
<time.h> Defines date and time handling functions
<uchar.h>C11Types and functions for manipulating Unicode characters.
<wchar.h>NA1Defines wide string handling functions.
<wctype.h>NA1Defines set of functions used to classify wide characters by their types or to convert between upper and lower case

参考资料


其他项目

外部链接


评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值