Your source file will have the include statements if your put it in the header. However, in some cases it would be better to put them in the source file.
If header file A #includes header files B and C, then every source file that #includes A will also get B and C #included. The pre-processor literally just performs text substitution: anywhere it finds text that says #include <foo.h> it replaces it with the text of foo.h file.
This means that it's entirely possible that header files might be included twice, and that can be a problem. The traditional method is to put "include guards" in header files, such as this for file foo.h:
#ifndef INCLUDE_FOO_H
#define INCLUDE_FOO_H
/* everything in header goes here */
#endif
There's been quite a bit of disagreement about this over the years. At one time, it was traditional that a header 只有 declare what was in whatever module it was related to, so 很多 headers had specific requirements that you #include a certain set of headers (in a specific order). Some extremely traditional C programmers still follow this model (religiously, in at least some cases).
在某些环境中,如果只包含所需的头文件,编译将是最快的。在其他环境中,如果所有源文件都可以使用相同的头的主要集合(有些文件可能在公共子集之外还有其他头) ,那么编译将得到优化。理想情况下,头应该构造成多个 # include 操作不会产生任何效果。最好在 # include 语句周围检查待包含文件的 include-Guard,尽管这样做会产生对该监护格式的依赖性。此外,根据系统的文件缓存行为,不必要的 # include 的目标最终完全被 # ifdef 化可能不会花费很长时间。