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++中的编译单元是如何定义的?
基础教程推荐
- 非静态 const 成员,不能使用默认赋值运算符 2022-10-09
- 为什么 RegOpenKeyEx() 在 Vista 64 位上返回错误代码 2021-01-01
- 如果我为无符号变量分配负值会发生什么? 2022-01-01
- 初始化列表*参数*评估顺序 2021-01-01
- 为什么 typeid.name() 使用 GCC 返回奇怪的字符以及如 2022-09-16
- 为什么派生模板类不能访问基模板类的标识符? 2021-01-01
- CString 到 char* 2021-01-01
- GDB 显示调用堆栈上函数地址的当前编译二进制文 2022-09-05
- 通过引用传递 C++ 迭代器有什么问题? 2022-01-01
- 我应该对 C++ 中的成员变量和函数参数使用相同的名称吗? 2021-01-01
