X $ C $Ç - 警告:隐函数的声明是在C99无效 [英] Xcode - Warning: Implicit declaration of function is invalid in C99
问题描述
获取一个警告:函数隐式声明斐波那契是C99无效。
怎么了?
的#include<&stdio.h中GT;INT主(INT ARGC,为const char * argv的[])
{
INT输入;
的printf(请给我一个数字:);
scanf函数(%d个,&安培;输入);
的getchar();
的printf(%d个斐波那契数为:%D,输入,斐波那契(输入)); //!} / * *主/INT斐波那契(INT数)
{
如果(数&下; = 1){
返回数;
}其他{
INT F = 0;
INT VV = 0;
INT V = 1;
的for(int i = 2; I< = getal; i ++){
F = VV + V;
VV = V;
V = F;
}
返回F;
}
} / * *斐波纳契/
该功能已被宣布它变得调用之前。这可以以各种方式来完成:
-
写下一个标题结果原型
使用此如果函数应当从多个源文件调用。只要写你的原型结果INT斐波那契(INT数);
结果
倒在.H
文件(例如:myfunctions.h
),然后的#includemyfunctions .H
在C code。 -
移动功能,它越来越被称为第一次结果之前,
这意味着,写下功能结果INT斐波那契(INT数){...}
结果
你的之前的主()
函数 -
显式声明的功能它越来越被称为第一次结果之前,
这是上面口味的组合:你的键入之前在C文件中的函数原型的main()
函数
作为一个附加说明:如果函数 INT斐波那契(INT数)
应只有在它执行的文件中使用的,应当宣告静态
,以便它仅在该翻译单元可见。
Getting a warning : Implicit declaration of function 'Fibonacci' is invalid in C99. What's wrong?
#include <stdio.h>
int main(int argc, const char * argv[])
{
int input;
printf("Please give me a number : ");
scanf("%d", &input);
getchar();
printf("The fibonacci number of %d is : %d", input, Fibonacci(input)); //!!!
}/* main */
int Fibonacci(int number)
{
if(number<=1){
return number;
}else{
int F = 0;
int VV = 0;
int V = 1;
for (int I=2; I<=getal; I++) {
F = VV+V;
VV = V;
V = F;
}
return F;
}
}/*Fibonacci*/
The function has to be declared before it's getting called. This could be done in various ways:
Write down the prototype in a header
Use this if the function shall be callable from several source files. Just write your prototype
int Fibonacci(int number);
down in a.h
file (e.g.myfunctions.h
) and then#include "myfunctions.h"
in the C code.Move the function before it's getting called the first time
This means, write down the function
int Fibonacci(int number){..}
before yourmain()
functionExplicitly declare the function before it's getting called the first time
This is the combination of the above flavors: type the prototype of the function in the C file before yourmain()
function
As an additional note: if the function int Fibonacci(int number)
shall only be used in the file where it's implemented, it shall be declared static
, so that it's only visible in that translation unit.
这篇关于X $ C $Ç - 警告:隐函数的声明是在C99无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!