C语言 防止头文件被多次引用

这里写代码片

comm.h和comm.c是公共模块。
test1.h和test1.c使用了公共模块。
test2.h和test2.c使用了了公共模块。
test.h和test.c使⽤用了了test1模块和test2模块。
这样最终程序中就会出现两份comm.h的内容。这样就造成了了文件内容的重复。

1.方法1

文件开头加上这一句就ok

#pragma once

2.方法2

将头文件放在“头文件”

ifndef __TEST_H__
#define __TEST_H__
//头文件
#endif //__TEST_H__

猜你喜欢

转载自blog.csdn.net/csdn_kou/article/details/80160031
今日推荐