回答
您正在使用编译器未见过声明的函数(“原型”)。
例如:
int main()
{
fun(2, "21"); /* The compiler has not seen the declaration. */
return 0;
}
int fun(int x, char *p)
{
/* ... */
}
您需要直接或在头前主来声明功能,这样,:
int fun(int x, char *p);
正确的方法是声明函数原型在头。
例main.h
#ifndef MAIN_H
#define MAIN_H
int some_main(const char *name);
#endif
的main.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
}
如果定义&正确的头使用非GlibC
库(如Musl C)gcc
也将抛出error: implicit declaration of function
遇到GNU扩展,如malloc_trim
时。
的解决方案是wrap the extension & the header:
#if defined (__GLIBC__)
malloc_trim(0);
#endif
当你得到error: implicit declaration of function
也应该列出有问题的功能。通常这个错误是由于一个被遗忘或丢失的头文件而发生的,所以在shell提示符下你可以输入man 2 functionname
并查看顶部的SYNOPSIS
部分,因为本节将列出需要包含的所有头文件。或者试试http://linux.die.net/man/这是他们超链接并且易于搜索的在线手册页。 函数通常在头文件中定义,包括任何需要的头文件通常都是答案。就像cnicutar说,
您正在使用该编译器还没有见过一个 声明(“原型”),但功能。
我认为这个问题不是100%的答案。我正在寻找缺少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
为conculsion的尝试使用,而不是__typeof__()
。另外gcc ... -Dtypeof=__typeof__ ...
可以提供帮助。
如果忘记包含头文件,也会发生这种情况。例如,如果您尝试在不包含string.h的情况下使用strlen(),您将得到此错误
当您在main.c中执行#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列表,只是不同的顺序。
嗯,它为我做了。
- 1. 警告:函数的隐式声明'crypt_r'
- 2. GLFW3:警告:隐式声明函数“glGenBuffers”
- 3. 警告:函数的隐式声明TableCreate
- 4. C警告隐式声明函数'exit'
- 5. dprintf隐式声明警告
- 6. 警告:隐式声明
- 7. sprintf_s()隐式声明警告
- 8. 隐式声明警告:什么是内置函数?
- 9. 为什么我会得到“隐式声明函数'PerformXMLXPathQuery'”警告?
- 10. 警告:隐式函数声明在C99中无效?
- 11. 如何删除以下'隐式函数声明'警告?
- 12. 警告:函数'foo'的隐式声明在C99中无效
- 13. Xcode - 警告:隐式函数声明在C99中无效
- 14. 防止“警告:函数的隐式声明”setlinebuf'...“
- 15. 警告:函数的隐式声明 - 包含事物的顺序?
- 16. 警告:隐式声明函数'getresuid'(和'seteuid')
- 17. GCC警告:函数'puts'的隐式声明在C99中无效
- 18. 警告的原因是什么:函数'swprintf_s'的隐式声明?
- 19. 警告:隐式声明的错误
- 20. 隐式函数声明usleep
- 21. 隐式函数声明NSMinX
- 22. 函数隐式声明'wiringPilSR'
- 23. 函数的隐式声明
- 24. 隐式函数声明'sched_setaffinity'
- 25. 隐式函数声明'usleep'
- 26. 函数隐式声明'dispatch_get_global_queue'
- 27. 函数的隐式声明?
- 28. ARC警告:函数'DLOG的内隐的声明是在C99
- 29. 函数的隐式声明'str [n] casecmp'[-Werror =隐式函数声明]
- 30. 任何函数的隐式声明的警告如何影响我的代码?
“为什么它不提供错误版本”:http://stackoverflow.com/questions/434763/are-prototypes-required-for-all-functions-in-c89-c90-or-c99 –