Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
头文件是翻译单元吗?如果我将 static 关键字添加到头文件中的变量,我可以在我的 .c 或 .cpp 文件中调用该变量吗?谢谢。
不,标题不是单独的翻译单元。
每个 .c/.cpp 文件都是一个单独的翻译单元,并且由于预处理器将#includes 文本替换为标头的内容,因此 .c/.cpp 文件包含(直接或间接)的所有标头中的代码是该文件的一部分翻译单元。
#include
换言之,翻译单元是经过预处理的 .c 或 .cpp 文件。
不,翻译单元是预处理器的全部输出。将包含一个头文件,其内容可能成为翻译单元的一部分。