C语言问题 关于implicit declaration of function

来源:互联网 发布:软件开发咨询 编辑:程序博客网 时间:2024/06/05 17:52

问题描述:在linux中用gcc编译三个文件:

$gcc linktable.c menu.c test.c -o menu -lm

产生警告:

test.c: In functionmain’:test.c:20:2: warning: implicit declaration of functionMenuConfig’ [-Wimplicit-function-declaration]  MenuConfig(cmd1, desc1, NULL);  ^test.c:43:2: warning: implicit declaration of functionExecuteMenu’ [-Wimplicit-function-declaration]  ExecuteMenu();  ^

两种情况会产生这种警告

  1. 没有把函数所在的c文件生成.o目标文件
  2. 在函数所在的c文件中定义了,但是没有在与之相关联的.h文件中声明

检查代码,发现test.c中的main函数调用了menu.c中的MenuConfig和ExecuteMenu函数,他们的原型在menu.h中定义:

int MenuConfig(char* cmd, char* desc, int (*handler)());int ExecuteMenu();

然而在test.c中却没有将menu.h包含进来,于是发生警告.好在编译器还是很智能的,即使没有#include这个头文件,还是能正常编译链接生成可执行文件.

https://zhidao.baidu.com/question/521511551.html

阅读全文
0 0