如何在C中包含标题

如何在C中包含标题,c,header,include,C,Header,Include,如何在c语言中包含头文件,以便包含包含头文件的文件不会包含头文件 例如: main.c 包括main.h main.h 包括测试 //我希望main.c不包括test.h 我想知道如何做到这一点使用定义: 总而言之 // the define MUST be before main.h inclusion #define IN_MAIN_C #include "main.h" 大体上 #ifndef IN_MAIN_C #include "test.h"

如何在c语言中包含头文件,以便包含包含头文件的文件不会包含头文件

例如:

main.c

包括main.h main.h

包括测试 //我希望main.c不包括test.h 我想知道如何做到这一点

使用定义:

总而言之

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

#ifndef IN_MAIN_C
#include "test.h"
#endif
使用定义:

总而言之

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

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

你可以使用条件编译在包含main.h和test之前只在main.c中定义宏我不想生成c代码,因为它对我没有帮助,但是谢谢你的反馈你可以使用条件编译在包含main.h和test之前只在main.c中定义一个宏我不想生成c代码,因为它对我没有帮助,但是谢谢你的反馈