有没有在那里,包括相同的头一两次的情况下实际上是有帮助吗? [英] Is there a case where including the same header twice is actually helpful?
问题描述
创建头看守我的H / HPP文件一直是标准的做法我,但我不知道,为什么它甚至可能包括取消同一个文件?有没有在您的实际需要未受保护的头一个呢?
Creating header guards for my h/hpp files has always been standard practice for me, but I wonder, why is it even possible to include de same file twice? Is there a case where you actually need unprotected headers?
推荐答案
参数头文件可以用来模拟C ++ - ISH风格模板C.在这种情况下,头文件将取决于许多宏( 模板参数)。它会根据这些宏的实际价值产生不同的code。
"Parameterized" header files can be used to simulate C++-ish-style templates in C. In such cases the header file will depend on a number of macros ("template parameters"). It will generate different code depending on the actual "value" of these macros.
所以,这样的报头的典型用法将如下的模板参数序列宏定义随后的#include
指令,其次是模板的另一个序列参数宏定义后面跟有相同的#include
,等等。
So, the typical usage of such header would look as a sequence of "template parameter" macro definitions followed by the #include
directive, followed by another sequence of "template parameter" macro definitions followed by the same #include
, and so on.
http://stackoverflow.com/a/7186396/187690
在使用这种技术,你会看到头文件时不包含任何警卫或头文件与包括只覆盖文件的一部分警卫。
When using this technique you will see header files without any include guards or header files with include guards that cover only a portion of the file.
这篇关于有没有在那里,包括相同的头一两次的情况下实际上是有帮助吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!