文件main.c中:
#include “test1.h”
#include “test2.h”
文件test2.h中:
#include “test1.h”
在test1.h中:
#ifndef TEST1__H
#define TEST1__H
#endif
在main.c中第一次调用test1时,发现未定义就执行#ifndef - #endif之间的代码,之后调用test2时就不再定义test1了。
如果test1中有定义变量之类的,就会报重定义的错误。
作用:防止重复定义