如何在c ++中定义编译单元? [英] How is compilation unit defined in c++?
问题描述
可能重复:
什么是翻译单位? in C ++
通常说的是在C / C ++中声明的静态变量在编译单元中不可见?这是否意味着每个.c或.cpp文件是一个单独的编译单元? h文件和.h文件中声明的静态变量怎么办?
头文件没有独立的生命,只有内容 #included
转换为.c或.cpp文件。但由于 #include
由预处理器处理,编译器不知道有关不同的头文件;它只看到生成的代码列表作为输入。这是所谓的编译单元:具有所有 #include
指令的源文件被相关头文件的内容替换。 p>
Possible Duplicate:
What is a “translation unit” in C++
It is often said that the static variables declared in C/C++ are not visible across compilation units ? Does this mean that each .c or .cpp file is a seperate compilation unit ? What about a ,h file and the static variables declared in the .h file ? Is .h file also considered as a separate compilation unit ?
Header files have no separate life, only their content is #included
into .c or .cpp files. But since #include
is handled by the preprocessor, the compiler has no knowledge about distinct header files; it only sees the resulting code listing as input. This is what is called a compilation unit: a source file with all its #include
directives replaced by the content of the relevant header files.
这篇关于如何在c ++中定义编译单元?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!