#include是否也意味着使用

Mar*_*arc 0 c++ include c-preprocessor

我想知道是否#include也意味着"使用".如果没有,你能否告诉我编译器将对额外文件,包含的函数做什么?如果是,这是否意味着他们在输出PE中分配了他们的记忆?

Naw*_*waz 7

#include "file.h"告诉预处理器打开file.h并将此文件的内容与您编写的当前文件合并#include "file.h".

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

//file.h
extern int x;

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

int x;
void f()
{
    x = 10;
}
Run Code Online (Sandbox Code Playgroud)

然后预处理器副本的内容file.hfile.cpp为:

extern int x; //came from file.h

int x;
void f()
{
    x = 10;
}
Run Code Online (Sandbox Code Playgroud)