我的编译器(GCC)给我警告:
警告:函数的隐式声明
它为什么会来?
我的编译器(GCC)给我警告:
警告:函数的隐式声明
它为什么会来?
当前回答
When you get the error: implicit declaration of function it should also list the offending function. Often this error happens because of a forgotten or missing header file, so at the shell prompt you can type man 2 functionname and look at the SYNOPSIS section at the top, as this section will list any header files that need to be included. Or try http://linux.die.net/man/ This is the online man pages they are hyperlinked and easy to search. Functions are often defined in the header files, including any required header files is often the answer. Like cnicutar said,
您正在使用的函数的编译器没有看到 声明(“原型”)。
其他回答
不要忘记,如果函数中调用了任何函数,它们的原型必须位于代码中函数的上方。否则,编译器在尝试编译函数之前可能找不到它们。这将产生问题中的错误。
在main.c中执行#includes时,将#include引用放在包含被引用函数的文件的include列表顶部。 例如,这是main.c,你引用的函数在“SSD1306_LCD.h”中
#include "SSD1306_LCD.h"
#include "system.h" #include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <string.h>
#include <math.h>
#include <libpic30.h> // http://microchip.wikidot.com/faq:74
#include <stdint.h>
#include <stdbool.h>
#include "GenericTypeDefs.h" // This has the 'BYTE' type definition
上面的代码不会生成“函数隐式声明”错误,但是下面的代码会生成-
#include "system.h"
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>
#include <string.h>
#include <math.h>
#include <libpic30.h> // http://microchip.wikidot.com/faq:74
#include <stdint.h>
#include <stdbool.h>
#include "GenericTypeDefs.h" // This has the 'BYTE' type definition
#include "SSD1306_LCD.h"
完全相同的#include列表,只是顺序不同。
对我来说确实如此。
When you get the error: implicit declaration of function it should also list the offending function. Often this error happens because of a forgotten or missing header file, so at the shell prompt you can type man 2 functionname and look at the SYNOPSIS section at the top, as this section will list any header files that need to be included. Or try http://linux.die.net/man/ This is the online man pages they are hyperlinked and easy to search. Functions are often defined in the header files, including any required header files is often the answer. Like cnicutar said,
您正在使用的函数的编译器没有看到 声明(“原型”)。
你正在使用一个编译器还没有看到声明(“原型”)的函数。
例如:
int main()
{
fun(2, "21"); /* The compiler has not seen the declaration. */
return 0;
}
int fun(int x, char *p)
{
/* ... */
}
你需要在main之前声明你的函数,像这样,直接或在头文件中声明:
int fun(int x, char *p);
GNU C编译器告诉您,它可以在程序作用域中找到特定的函数名。尝试在头文件中将其定义为私有原型函数,然后将其导入到主文件中。