警告:隐含的功能声明 - 包含物质的顺序?

时间:2016-09-13 01:11:54

标签: c warnings declaration implicit

我有一个来自main.c的代码示例代码片段,它调用了3个函数,带有3个头文件 - 这给了我一个未知原因的警告:



#include "header1.h"
#include "header2.h"
#include "header3.h"

int main()
{
  function1(); // this is from header1
  function2(); // this is from header2
  function3(); // this is from header 3
} 




基本上,使用gcc后,功能2& 3会产生警告。但是,在重新排列代码之后:



#include "header3.h"
#include "header1.h"
#include "header2.h"
   

int main()
{
  function1(); // this is from header1
  function2(); // this is from header2
  function3(); // this is from header 3
} 




然后它会给我警告功能1& 2是隐含的。我在这里做错了什么?

1 个答案:

答案 0 :(得分:1)

您的包含文件1应如下所示:

#ifndef __REZON_FUNCTIONS1__ 
#define __REZON_FUNCTIONS1__ 

#endif

其他两个文件应该相似,宏名称也相应改变