我做了几年的程序员。
我总是被告知(并告诉其他人)你应该在你的 .c 文件中只包含你需要的 .h 文件。不多也不少。
但让我问 - 为什么?
使用今天的编译器,我可以包含项目的整个 h 文件,并且不会对编译时间产生巨大影响。
我不是在谈论包括 OS .h 文件,其中包括许多定义、宏和预处理命令。
只包括一个“MyProjectIncludes.h”。那只会说:
#pragma once
#include "module1.h"
#include "module2.h"
// and so on for all of the modules in the project
你说什么?