如何在C中私下包含标头

杜克利特

如何在c中私下包含头文件,以便包含头文件的文件不会包含头文件。

例如:

main.c

#include "main.h"

main.h

#include "test.h"
// I want main.c not to include test.h

我想知道怎么做

让·弗朗索瓦·法布尔

使用#define

在main.c中

// the define MUST be before main.h inclusion
#define IN_MAIN_C
#include "main.h"

在main.h中

#ifndef IN_MAIN_C
#include "test.h"
#endif

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章