How is compilation unit defined in 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++中的编译单元是如何定义的?
				
        
 
            
        基础教程推荐
- 这个宏可以转换成函数吗? 2022-01-01
 - 如何通过C程序打开命令提示符Cmd 2022-12-09
 - 在 C++ 中计算滚动/移动平均值 2021-01-01
 - C++结构和函数声明。为什么它不能编译? 2022-11-07
 - 我有静态或动态 boost 库吗? 2021-01-01
 - 常量变量在标题中不起作用 2021-01-01
 - 如何检查GTK+3.0中的小部件类型? 2022-11-30
 - 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01
 - 如何在 C++ 中初始化静态常量成员? 2022-01-01
 - 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				