Xcode - 警告:函数的隐式声明在 C99 中无效 [英] Xcode - Warning: Implicit declaration of function is invalid in C99

查看:77
本文介绍了Xcode - 警告:函数的隐式声明在 C99 中无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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:

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

  • 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.

在函数第一次被调用之前移动它
这意味着,写下函数
int Fibonacci(int number){..}
在你的 main() 函数之前

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

另外说明:如果函数 int Fibonacci(int number) 只在实现它的文件中使用,它应该被声明为 static,这样它仅在该翻译单元中可见.

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.

这篇关于Xcode - 警告:函数的隐式声明在 C99 中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆