#include 是否也意味着使用
我想知道#include 是否也意味着“使用”。如果没有,请告诉我编译器将如何处理额外的文件和包含的函数?如果是,这是否意味着它们的内存分配在输出 PE 中?
I wonder whether #include
also means "use". If not, would you please tell me what the compiler will do with the extra files, included functions? If yes, does this mean they have their memories allocated in the output PE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
#include "file.h"
告诉预处理器打开file.h
并将该文件的内容与您在其中写入#include " 的当前文件合并文件.h”
。也就是说,如果您有两个文件:
然后预处理器将
file.h
的内容复制到file.cpp
,如下所示:#include "file.h"
tells the preprocessor to openfile.h
and merge the content of this file with the current file in which you write#include "file.h"
.That is, if you have two files as:
Then preprocessor copies the content of
file.h
tofile.cpp
as:Include 表示打开文件,该文件的名称是 include 的参数,并且(实际上)将其文本放入当前文件中。编译器的工作方式与所有文件合并为一个文件的方式相同。
因此,在大多数情况下,包含的文件是头文件。它们用于声明函数、宏、类、外部变量;因此您可以在多个源文件(例如
src1.c
、src2.c
)中包含头文件(例如file.h
),并且在这两个源中,您将预定义相同的一组函数/类/外部函数。Include means open the file, which name is parameter of include and (virtually) put its text in the current file. Compiler will work in same way as if all files were combined into single one.
So, At most cases, included files are header files. They are used to declare functions, macros, classes, extern variables; so you can include a header file (e.g.
file.h
) in the several source files (e.g.src1.c
,src2.c
) and in both sources you will have the same set of functions/classes/extern functions predefined.Include 只是复制包含文件的内容作为编译的第一阶段。 (预处理器)。这通常用于添加头文件,但也可用于包含任何其他类型的文件。所以经常用来添加内联代码的文件。有时,在开发代码时,您可能希望包含另一个包含代码的文件。
Include just copies the contents of the included file as the first stage of compilation. (The pre-processor). This is usually to add header files but can also be used to include any other sort of file. So it is often used to add files with inline code. Sometimes while developing code you may want to include another file with code in.