这个问题在这里已经有了答案:
头文件只在整个程序中包含一次? 4个答案当file1.c inc.h包含inc.h (包含include guard #ifndef INC_H )时,执行#define INC_H 。 但是现在,当另一个file2.c包含相同的inc.h ,是否已经定义了宏INC_H ,它们都是相同的故事,并且以前的定义不会在这里传播?
This question already has an answer here:
Header file included only once in entire program? 4 answersWhen file1.c includes inc.h (containing the include guard #ifndef INC_H) for the first time, the #define INC_H is performed. But now, when another file2.c includes the same inc.h, is the macro INC_H already defined, all it's the same story and previous definition is not propagated here?
最满意答案
但是现在,当另一个file2.c包含相同的inc.h时,已经定义了宏INC_H,
是和不,这取决于。
如果file2.c包含一些包含inc.h头文件,那么是的 , INC_H已经为file2.c定义了。 这对于任何包含水平都是如此。
否则, 不,它尚未定义。
守卫防止头被间接或直接包含在文件中,不止一次!
But now, when another file2.c includes the same inc.h, is the macro INC_H already defined,
Yes and No. It depends.
If file2.c includes some header which includes inc.h, then yes, INC_H is already defined for file2.c. This is true for any level of inclusion.
Else, no it is not already defined.
Guards prevent header from being included in a file, indirectly or directly, more than once!
更多推荐
发布评论