C头后卫 [英] C include guard
问题描述
在 file1.c中
包括 inc.h
(含包括后卫的#ifndef INC_H
)的第一次,执行的#define INC_H
。但是现在,当另一个 file2.c中
包含相同的 inc.h
,是宏 INC_H
已定义的,它所有的同样的故事和previous定义不在这里繁殖?
但现在,当另一file2.c中包括相同inc.h,已定义的宏INC_H,
块引用>是和否这要看情况。
如果
file2.c中
包括一些头,其中包括inc.h
和是,INC_H
已经为file2.c中
定义。这是列入任何级别如此。否则,否尚未确定。
护罩$ P从被包括在一个文件中,直接或间接地$ pvent头,不止一次!
When
file1.c
includesinc.h
(containing the include guard#ifndef INC_H
) for the first time, the#define INC_H
is performed. But now, when anotherfile2.c
includes the sameinc.h
, is the macroINC_H
already defined, all it's the same story and previous definition is not propagated here?解决方案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 includesinc.h
, then yes,INC_H
is already defined forfile2.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!
这篇关于C头后卫的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!