C包括后卫[复制](C include guard [duplicate])

编程入门 行业动态 更新时间:2024-10-26 04:28:51
C包括后卫[复制](C include guard [duplicate])

这个问题在这里已经有了答案:

头文件只在整个程序中包含一次? 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 answers

When 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!

更多推荐

本文发布于:2023-08-04 08:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1412413.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后卫   include   duplicate   guard

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!