[英]Xcode - Warning: Implicit declaration of function is invalid in C99
Getting a warning: Implicit declaration of function 'Fibonacci' is invalid in C99.收到警告:function 'Fibonacci' 的隐式声明在 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 (eg myfunctions.h
) and then #include "myfunctions.h"
in the C code. 在
.h
文件中(例如myfunctions.h
),然后在C代码中#include "myfunctions.h"
。
Move the function before it's getting called the first time 在第一次调用函数之前移动该函数
This means, write down the function 这意味着,记下这个功能
int Fibonacci(int number){..}
before your main()
function 在
main()
函数之前
Explicitly 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 your main()
function 这是上述风格的组合:在
main()
函数之前在C文件中键入函数的原型
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. 另外要注意:如果函数
int Fibonacci(int number)
只能在它实现的文件中使用,它应该被声明为static
,因此它只在该转换单元中可见。
The compiler wants to know the function before it can use it 编译器想要在使用它之前知道该函数
just declare the function before you call it 只需在调用之前声明该函数
#include <stdio.h>
int Fibonacci(int number); //now the compiler knows, what the signature looks like. this is all it needs for now
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)
{
//…
in c The function has to be declared before it's getting called在 c function 必须在它被调用之前声明
include head file包含头文件
I have the same warning (it's make my app cannot build). 我有同样的警告(它使我的应用程序无法构建)。 When I add
C function
in Objective-C's .m file
, But forgot to declared it at .h
file. 当我在
Objective-C's .m file
添加C function
时,但忘了在.h
文件中声明它。
should call the function properly; 应该正确地调用该功能; like- Fibonacci:input
喜欢斐波纳契:输入
I also need to use DMA sd card writing and this example doesn't work.我还需要使用 DMA sd 卡写入,这个例子不起作用。 I think the problem is I use 32gb sd inside of 1gb or 2gb.
我认为问题是我在 1gb 或 2gb 中使用 32gb sd。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.