场景如下:
文件.h
#ifndef _FILE_
#define _FILE_
void foo(void);
#endif
文件.c
#include "file.h" //why is this line necessary?
void foo(void)
{
do something here...
}
最佳答案
这样做是为了捕获头文件中的函数声明与.c 文件中的函数定义之间的不一致。例如,以下将从编译器生成错误消息
文件.h
#ifndef _FILE_
#define _FILE_
void foo(void);
#endif
文件.c
#include "file.h" //This line is for error checking
void foo( int someArgThatWasntInTheDeclaration )
{
do something here...
}
关于c - 为什么在多个编译单元项目中需要将 file.h 文件包含到 file.c 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32245258/