我的编译器(Gcc)警告我:
警告:函数的隐式声明
请帮我弄明白为什么会来。
发布于 2018-03-23 13:33:25
例如:
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);
发布于 2018-03-23 14:59:33
正确的方法是在标头中声明函数原型。
#ifndef MAIN_H
#define MAIN_H
int some_main(const char *name);
#endif
#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
}
https://stackoverflow.com/questions/-100003674
复制相似问题