C90编译器抱怨无原型函数警告
我在includes.h文件中声明了一个函数C90编译器抱怨无原型函数警告,c,compilation,compiler-warnings,C,Compilation,Compiler Warnings,我在includes.h文件中声明了一个函数hello() hello()函数在source.c文件中定义 在main.c文件中调用hello()函数 包含。h包含以下代码 /* * includes.h * * Created on: Jul 26, 2018 * Author: salim */ #ifndef T_HEADER_H_ #define T_HEADER_H_ #include &l
hello()
hello()
函数在source.c文件中定义
在main.c文件中调用hello()
函数
包含。h包含以下代码
/*
* includes.h
*
* Created on: Jul 26, 2018
* Author: salim
*/
#ifndef T_HEADER_H_
#define T_HEADER_H_
#include <stdio.h>
int hello();
#endif /* T_HEADER_H_ */
/*
* source.c
*
* Created on: Jul 26, 2018
* Author: salim
*/
#include <stdio.h>
#include "includes.h"
int hello()
{
printf("Hello, World!");
return 0;
}
/*
* main.c
*
* Created on: Jul 26, 2018
* Author: salim
*/
#include <stdio.h>
#include "includes.h"
int main()
{
hello();
return 0;
}
/*
*包括.h
*
*创建日期:2018年7月26日
*作者:萨利姆
*/
#ifndef T_头\u H_
#定义标题_
#包括
int hello();
#endif/*T_头*/
source.c包含以下代码
/*
* includes.h
*
* Created on: Jul 26, 2018
* Author: salim
*/
#ifndef T_HEADER_H_
#define T_HEADER_H_
#include <stdio.h>
int hello();
#endif /* T_HEADER_H_ */
/*
* source.c
*
* Created on: Jul 26, 2018
* Author: salim
*/
#include <stdio.h>
#include "includes.h"
int hello()
{
printf("Hello, World!");
return 0;
}
/*
* main.c
*
* Created on: Jul 26, 2018
* Author: salim
*/
#include <stdio.h>
#include "includes.h"
int main()
{
hello();
return 0;
}
/*
*资料来源c
*
*创建日期:2018年7月26日
*作者:萨利姆
*/
#包括
#包括“包括.h”
int hello()
{
printf(“你好,世界!”);
返回0;
}
main.c包含以下代码
/*
* includes.h
*
* Created on: Jul 26, 2018
* Author: salim
*/
#ifndef T_HEADER_H_
#define T_HEADER_H_
#include <stdio.h>
int hello();
#endif /* T_HEADER_H_ */
/*
* source.c
*
* Created on: Jul 26, 2018
* Author: salim
*/
#include <stdio.h>
#include "includes.h"
int hello()
{
printf("Hello, World!");
return 0;
}
/*
* main.c
*
* Created on: Jul 26, 2018
* Author: salim
*/
#include <stdio.h>
#include "includes.h"
int main()
{
hello();
return 0;
}
/*
*main.c
*
*创建日期:2018年7月26日
*作者:萨利姆
*/
#包括
#包括“包括.h”
int main()
{
你好;
返回0;
}
编译通过,但编译器生成一条信息消息,说明main.c(11):C0200(I)无原型函数
我错过了什么来消除信息/警告信息?我知道,一个解决办法可能是转而显示警告/信息消息,但我不想走这条路。正式地说,在调用时,这是一个“无原型功能”int hello()
不是原型。它是“非原型”类型的函数声明。这是一个K&R风格的声明
此函数的原型声明如下所示
int hello(void);
这是否是编译器试图告诉您的(或者存在其他问题)是另一个问题。正式地说,在调用时它是一个“无原型函数”int hello()
不是原型。它是“非原型”类型的函数声明。这是一个K&R风格的声明
此函数的原型声明如下所示
int hello(void);
这是否是编译器试图告诉您的(或者有其他问题)是另一个问题。在我看来没问题。您正在使用什么操作系统和编译器,以及在命令行上键入什么来编译这些文件?您应该定义并声明
inthello(void)
。由于历史原因(K&R日),未声明任何参数表示“参数未定义”,在这种情况下,编译器通常会发出警告,因为它们无法在调用function@squeamishossifrage我正在使用日立C/C++编译器编译ubuntu 16.04,谢谢。正如在接受的答案中指出的,这是函数的K&R声明的一个问题,我必须显式地指定void,因为函数参数hello(void)在我看来是正确的。您正在使用什么操作系统和编译器,以及在命令行上键入什么来编译这些文件?您应该定义并声明inthello(void)
。由于历史原因(K&R日),未声明任何参数表示“参数未定义”,在这种情况下,编译器通常会发出警告,因为它们无法在调用function@squeamishossifrage我正在使用日立C/C++编译器编译ubuntu 16.04,谢谢。正如在接受的回答中指出的,这是函数的K&R声明的问题,我必须明确指定void作为函数参数hello(void),信息消息仍然显示在内置的C函数中,即退出(3)并包含适当的头(#include),这种情况也有解决办法吗?@salimsaid可能不是原因,但是退出的正确标题是
,而不是
。很抱歉,我错了,我实际上没有包括在内,如果是这样的话,应该会使警告静音。信息消息仍然显示,带有内置的C函数,即退出(3)如果包含正确的标题(#include),是否也有解决此问题的方法?@salimsaid可能不是原因,但是exit
的正确标题是
,而不是
。很抱歉,我错了,我实际上没有包含,如果是这样的话,应该使警告静音。