#include 是否也意味着使用

发布于 2024-11-29 04:18:08 字数 86 浏览 0 评论 0原文

我想知道#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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

疯到世界奔溃 2024-12-06 04:18:08

#include "file.h" 告诉预处理器打开 file.h 并将该文件的内容与您在其中写入 #include " 的当前文件合并文件.h”

也就是说,如果您有两个文件:

//file.h
extern int x;

//file.cpp
#include "file.h"

int x;
void f()
{
    x = 10;
}

然后预处理器将 file.h 的内容复制到 file.cpp ,如下所示:

extern int x; //came from file.h

int x;
void f()
{
    x = 10;
}

#include "file.h" tells the preprocessor to open file.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:

//file.h
extern int x;

//file.cpp
#include "file.h"

int x;
void f()
{
    x = 10;
}

Then preprocessor copies the content of file.h to file.cpp as:

extern int x; //came from file.h

int x;
void f()
{
    x = 10;
}
清晨说晚安 2024-12-06 04:18:08

Include 表示打开文件,该文件的名称是 include 的参数,并且(实际上)将其文本放入当前文件中。编译器的工作方式与所有文件合并为一个文件的方式相同。

因此,在大多数情况下,包含的文件是头文件。它们用于声明函数、宏、类、外部变量;因此您可以在多个源文件(例如src1.csrc2.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.

﹂绝世的画 2024-12-06 04:18:08

Include 只是复制包含文件的内容作为编译的第一阶段。 (预处理器)。这通常用于添加头文件,但也可用于包含任何其他类型的文件。所以经常用来添加内联代码的文件。有时,在开发代码时,您可能希望包含另一个包含代码的文件。

#include <header.h>
#include <inlines.inl>
#include "testcode.cpp"

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.

#include <header.h>
#include <inlines.inl>
#include "testcode.cpp"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文