stdio.h 是图书馆吗?
Is stdio.h a library?
C 编程语言 调用stdio.h
一个库。但是,有人告诉我这是一个 头文件 仅供编译器使用,这是真的,因此它不是一个库。
Internet 上的其他编程站点将其称为库。现在 library 的定义不一样了吗?
一些C程序以#include <stdio.h>
开头,因为C语言不包含文件操作函数。
更新引用来自 Brian Kernighan 和 Dennis Ritchie 的 The C Programming Language,第二版,第 3 页(简介):
A second significant contribution of the standard [ refers to "the ANSI standard, or "ANSI C", completed in 1988] is the definition of a library of accompany C. It specifies functions for accessing the operating system (for instance to read and write files), formatted input and output, memory allocation, string manipulation, and the like. ... Programs that use this library to interact with a host system are assured of compatible behavior. Most of the library is clostly modeled on the "standard I/O library" of the UNIX system. This library was described in the first edition ...
library 的定义有 evolved/changed/updated...
这似乎是一个合乎逻辑的结论
不,stdio.h
不是一个库,它是一个头文件。接触 C 时的一个常见错误是将每个头文件都称为库,这是错误的。
C标准库是函数的集合,在头文件中声明,stdio.h
就是其中之一。该名称代表 "Standard Input Output",因此在该文件中您可以找到所有处理输入、输出和文件的函数声明。您可以找到 C 标准库中包含的头文件列表 here.
一个库是一个编译的二进制文件(或者一般来说,二进制文件的集合),在编译程序时可以linked利用图书馆提供的功能(即导出)。然后使用头文件来识别这些函数的名称和签名,以便编译器知道如何调用它们。
通常对于小型库来说,一个头文件就足够了,所以初学者很容易将头文件与库本身混淆。但是C标准库很复杂,函数很多,所以声明在不同的头文件中。
C programs start with #include <stdio.h>
because the C language does not include file manipulation functions.
是的,没错。 C规范只涉及语言本身(语法、类型等),并没有定义任何"standard"函数。
My book, "The C Programming Language" calls stdio.h a library. Now, I am being told that it's a "header file" only meant for the compiler, which is true, and therefore it's not a library.
我有那本书的副本(第一版,还有 ANSI 版),我不记得对 header 文件和库之间的区别有任何混淆。你能告诉我们你在找什么吗?例如,在第 152 页,我看到:
Each source file that refers to an input/output library function must
contain the line
#include <stdio.h>
这很对...这并不是说 stdio.h
是一个 库,而是说您必须包含 header 文件,如果你想使用图书馆。同样在第 176 页:
The data structure that describes a file is contained in ,
which must be included (by #include) in any source file that uses
routines from the standard input/output library. It is also included
by functions in that library...
在本段中 库 指的是 "the standard input/output library," 而不是 stdio.h
本身。我知道有人可能会误读它,但在上下文中,这本书实际上并没有在这里称 stdio.h
图书馆。
如果您可以指出您正在查看的特定段落,也许我们可以更好地解释。
更新:
你在书中引用的那段话是从第二版的介绍开始的,它讲的是到那时为止的语言历史(第二版于 1988 年出版)。特别是,该段是在谈论 C 标准库:
A second significant contribution of the standard is the definition of a library to accompany C...
看起来激发您问题的部分是:
...Most of the library is closely modeled on the "standard 1/0 library" of the UNIX system. This library was described in the first edition, and has been widely used on other systems as well...
在所有情况下,当文本说 library 时,它的真正意思是,而不是 header file。每个 C 库都有一个或多个关联的 header 文件,这些文件提供关联库的接口;没有 header(s),您(和您的编译器)将不知道如何访问库中定义的函数。例如,fopen()
函数在stdio.h
中声明,函数原型为:
FILE *
fopen(const char * restrict path, const char * restrict mode);
一旦你有了 fopen()
的声明,编译器就知道如何生成调用该函数的指令,链接器会将你的代码连接到实际的函数 definition 在库文件本身。所以当文字说 standard I/O library 时,它实际上是在谈论库,而同名的 header 文件只是一个辅助文件,可以让你访问图书馆。
It would seem a logical conclusion that the definition of library has evolved/changed/updated...
不,事实并非如此; header 文件和库是并且一直是不同但相关的东西,自本书编写以来,其含义确实没有改变,至少在 C 方面是这样。
C 编程语言 调用stdio.h
一个库。但是,有人告诉我这是一个 头文件 仅供编译器使用,这是真的,因此它不是一个库。
Internet 上的其他编程站点将其称为库。现在 library 的定义不一样了吗?
一些C程序以#include <stdio.h>
开头,因为C语言不包含文件操作函数。
更新引用来自 Brian Kernighan 和 Dennis Ritchie 的 The C Programming Language,第二版,第 3 页(简介):
A second significant contribution of the standard [ refers to "the ANSI standard, or "ANSI C", completed in 1988] is the definition of a library of accompany C. It specifies functions for accessing the operating system (for instance to read and write files), formatted input and output, memory allocation, string manipulation, and the like. ... Programs that use this library to interact with a host system are assured of compatible behavior. Most of the library is clostly modeled on the "standard I/O library" of the UNIX system. This library was described in the first edition ...
library 的定义有 evolved/changed/updated...
这似乎是一个合乎逻辑的结论不,stdio.h
不是一个库,它是一个头文件。接触 C 时的一个常见错误是将每个头文件都称为库,这是错误的。
C标准库是函数的集合,在头文件中声明,stdio.h
就是其中之一。该名称代表 "Standard Input Output",因此在该文件中您可以找到所有处理输入、输出和文件的函数声明。您可以找到 C 标准库中包含的头文件列表 here.
一个库是一个编译的二进制文件(或者一般来说,二进制文件的集合),在编译程序时可以linked利用图书馆提供的功能(即导出)。然后使用头文件来识别这些函数的名称和签名,以便编译器知道如何调用它们。
通常对于小型库来说,一个头文件就足够了,所以初学者很容易将头文件与库本身混淆。但是C标准库很复杂,函数很多,所以声明在不同的头文件中。
C programs start with
#include <stdio.h>
because the C language does not include file manipulation functions.
是的,没错。 C规范只涉及语言本身(语法、类型等),并没有定义任何"standard"函数。
My book, "The C Programming Language" calls stdio.h a library. Now, I am being told that it's a "header file" only meant for the compiler, which is true, and therefore it's not a library.
我有那本书的副本(第一版,还有 ANSI 版),我不记得对 header 文件和库之间的区别有任何混淆。你能告诉我们你在找什么吗?例如,在第 152 页,我看到:
Each source file that refers to an input/output library function must contain the line
#include <stdio.h>
这很对...这并不是说 stdio.h
是一个 库,而是说您必须包含 header 文件,如果你想使用图书馆。同样在第 176 页:
The data structure that describes a file is contained in , which must be included (by #include) in any source file that uses routines from the standard input/output library. It is also included by functions in that library...
在本段中 库 指的是 "the standard input/output library," 而不是 stdio.h
本身。我知道有人可能会误读它,但在上下文中,这本书实际上并没有在这里称 stdio.h
图书馆。
如果您可以指出您正在查看的特定段落,也许我们可以更好地解释。
更新:
你在书中引用的那段话是从第二版的介绍开始的,它讲的是到那时为止的语言历史(第二版于 1988 年出版)。特别是,该段是在谈论 C 标准库:
A second significant contribution of the standard is the definition of a library to accompany C...
看起来激发您问题的部分是:
...Most of the library is closely modeled on the "standard 1/0 library" of the UNIX system. This library was described in the first edition, and has been widely used on other systems as well...
在所有情况下,当文本说 library 时,它的真正意思是,而不是 header file。每个 C 库都有一个或多个关联的 header 文件,这些文件提供关联库的接口;没有 header(s),您(和您的编译器)将不知道如何访问库中定义的函数。例如,fopen()
函数在stdio.h
中声明,函数原型为:
FILE *
fopen(const char * restrict path, const char * restrict mode);
一旦你有了 fopen()
的声明,编译器就知道如何生成调用该函数的指令,链接器会将你的代码连接到实际的函数 definition 在库文件本身。所以当文字说 standard I/O library 时,它实际上是在谈论库,而同名的 header 文件只是一个辅助文件,可以让你访问图书馆。
It would seem a logical conclusion that the definition of library has evolved/changed/updated...
不,事实并非如此; header 文件和库是并且一直是不同但相关的东西,自本书编写以来,其含义确实没有改变,至少在 C 方面是这样。