c++中的编译单元是如何定义的?

How is compilation unit defined in c++?(c++中的编译单元是如何定义的?)

本文介绍了c++中的编译单元是如何定义的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
什么是翻译单元"在 C++ 中

常说C/C++中声明的静态变量在编译单元中是不可见的?这是否意味着每个 .c 或 .cpp 文件都是一个单独的编译单元?.h 文件和 .h 文件中声明的静态变量呢?.h 文件是否也被视为单独的编译单元?

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 ?

推荐答案

头文件没有独立的生命,只有它们的内容是#included 到.c 或.cpp 文件中.但是由于 #include 由预处理器处理,编译器不知道不同的头文件;它只将生成的代码列表视为输入.这就是所谓的编译单元:一个源文件,其所有#include 指令都被相关头文件的内容所取代.

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++中的编译单元是如何定义的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:c++中的编译单元是如何定义的?