Sun Studio 12:C 用户指南

B.2.124.6 浏览头文件以查找问题

如何能够使头文件可以预编译?在不同的源文件中解释一致时,头文件可以预编译。具体来说,就是当它仅包含完全声明时。也就是说,任何一个文件中的声明都必须独自成为有效声明。不完全的类型声明,例如 struct S;,是有效声明。完全类型声明可以出现在某些其他文件中。请考虑这些头文件示例:


file a.h
struct S {
#include "x.h" /* not allowed */
};

file b.h
struct T; // ok, complete declaration
struct S {
   int i;
[end of file, continued in another file] /* not allowed*/

并入预编译头文件的头文件一定不得违反以下约束。这里没有定义对违反上述约束的程序的编译结果。