开发者

Does #include also mean Use

开发者 https://www.devze.com 2023-03-28 01:54 出处:网络
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 alloc

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 alloc开发者_Python百科ated in the output PE?


#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;
}


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 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"
0

精彩评论

暂无评论...
验证码 换一张
取 消