我的编译器(GCC)给我警告:
警告:函数的隐式声明
它为什么会来?
我的编译器(GCC)给我警告:
警告:函数的隐式声明
它为什么会来?
当前回答
我认为这个问题并没有百分之百的答案。我正在寻找缺少typeof()的问题,这是编译时指令。
以下链接将有助于了解情况:
https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Typeof.html
https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Alternate-Keywords.html#Alternate-Keywords
作为结论,尝试使用__typeof__()代替。还有gcc…-Dtypeof = __typeof__……能帮上忙。
其他回答
你需要在主函数之前声明你想要的函数:
#include <stdio.h>
int yourfunc(void);
int main(void) {
yourfunc();
}
我认为这个问题并没有百分之百的答案。我正在寻找缺少typeof()的问题,这是编译时指令。
以下链接将有助于了解情况:
https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Typeof.html
https://gcc.gnu.org/onlinedocs/gcc-5.3.0/gcc/Alternate-Keywords.html#Alternate-Keywords
作为结论,尝试使用__typeof__()代替。还有gcc…-Dtypeof = __typeof__……能帮上忙。
你正在使用一个编译器还没有看到声明(“原型”)的函数。
例如:
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);
在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列表,只是顺序不同。
对我来说确实如此。
正确的方法是在头文件中声明函数原型。
例子
main.h
#ifndef MAIN_H
#define MAIN_H
int some_main(const char *name);
#endif
c
#include "main.h"
int main()
{
some_main("Hello, World\n");
}
int some_main(const char *name)
{
printf("%s", name);
}
用一个文件替代(main.c)
static int some_main(const char *name);
int some_main(const char *name)
{
// do something
}