比如:在C语言中,假如文件A调用的函数int DisplayInit(void)
在文件B中被定义,而函数DisplayInit()的函数体中用到了结构体“struct DispOpr”,这个结构体是在头文件disp_manager.h中定义的,显然,文件B中是要包含头文件disp_manager.h的,那么现在问题来了,请问文件A中是否也要包含头文件disp_manager.h?
文件A是否需要包含disp_manager.h
,取决于以下这个因素:
文件A是否直接使用了struct DispOpr
-
如果文件A中直接使用了
struct DispOpr
(例如定义变量、传递参数、访问成员),那么文件A需要包含disp_manager.h
,因为只有包含这个头文件,文件A才能知道结构体struct DispOpr
的完整定义。 -
如果文件A只调用了
DisplayInit()
函数,而并没有直接使用struct DispOpr
,则文件A不需要包含disp_manager.h
。在这种情况下,文件A中只需要知道DisplayInit()
的声明,而不需要了解其内部实现。
具体场景举例
情况1:文件A
直接使用了struct DispOpr
#