圆形的#includes是如何解决的? [英] How are circular #includes resolved?

查看:125
本文介绍了圆形的#includes是如何解决的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C可以说我们有2个文件

In c lets say we have 2 files

1.h

#include<2.h>

blah blah

和我们有
     2.H

and we have 2.h

#include<1.h>

code

这是怎么解决的?

推荐答案

通常情况下保护您的包含文件与IFNDEF /定义对应文件名。这并不prevent再次被包括在文件,但它被用来做prevent内容(的#ifndef内部)和触发递归再次包括

Typically you protect your include file with an ifndef/define that corresponds to the file name. This doesn't prevent the file from being included again, but it does prevent the contents (inside the ifndef) from being used and triggering the recursive includes again.

 #ifndef HEADER_1_h
 #define HEADER_1_h

 #include "2.h"

 /// rest of 1.h

 #endif

 #ifndef HEADER_2_h
 #define HEADER_2_h

 #include "1.h"

 //  rest of 2.h

 #endif

这篇关于圆形的#includes是如何解决的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆