繁体   English   中英

Xcode - 警告:function 的隐式声明在 C99 中无效

[英]Xcode - Warning: Implicit declaration of function is invalid in C99

收到警告:function 'Fibonacci' 的隐式声明在 C99 中无效。 怎么了?

#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*/

该函数必须在被调用之前声明。 这可以通过各种方式完成:

  • 在标题中写下原型
    如果函数可以从多个源文件中调用,请使用此选项。 只需编写原型
    int Fibonacci(int number);
    .h文件中(例如myfunctions.h ),然后在C代码中#include "myfunctions.h"

  • 在第一次调用函数之前移动该函数
    这意味着,记下这个功能
    int Fibonacci(int number){..}
    main()函数之前

  • 在第一次调用函数之前显式声明该函数
    这是上述风格的组合:在main()函数之前在C文件中键入函数的原型

另外要注意:如果函数int Fibonacci(int number)只能在它实现的文件中使用,它应该被声明为static ,因此它只在该转换单元中可见。

编译器想要在使用它之前知道该函数

只需在调用之前声明该函数

#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)
{
//…

在 c function 必须在它被调用之前声明

包含头文件

我有同样的警告(它使我的应用程序无法构建)。 当我在Objective-C's .m file添加C function时,但忘了在.h文件中声明它。

应该正确地调用该功能; 喜欢斐波纳契:输入

我还需要使用 DMA sd 卡写入,这个例子不起作用。 我认为问题是我在 1gb 或 2gb 中使用 32gb sd。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM