看了PLAUCER的书。才发现对经典的标准C库知之甚少,用过但没系统的学习过,现在通过PLAUCER的书好好的研究一下吧!
PLAUCER对库的定义:A library is a collection of program components that can be reused in many programs. Most programming languages include some form of library. The programming language C is no exception. It began accreting useful functions right from the start. These functions help you classify characters, manipulate character strings, read input, and write output -to name just a few categories of services。
标准C库共在15个头文件中做出声明,还包含对相关的类型和宏的定义:<assert.h><locale.h><stddef.h><stype.h><math.h><stdio.h><errno.h><setjmp.h><stdlib.h><float.h><signal.h><string.h><limits.h><stdarg.h><time.h>。
对于头文件的定义有Idempotence、mutual independence和declaration equivalence三条准则:
就我自己的理解所谓的Idempotence就是为了不让头文件重复定义,在开头用宏把头文件保护起来:
#ifndef _STDIO_H
#define _STDIO_H
..../* the body of <stdio.h> */
#endif
这样已经定义的头文件就不会被再次定义。
mutual independence就是在不同的头文件中可能有一个名字进行了分别定义,为了保证不出错我们也要利用宏包这样的定义保护起来:
#ifndef _SIZE_T
#define _SIZE_T
typedef unsigned int size_t;
#endif