且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

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

更新时间:2022-12-16 09:23:40

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

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.