【发布时间】:2020-06-23 05:30:47
【问题描述】:
我有一个项目,其中包含三个代码块中的文件:
main.c:
#include <stdio.h>
#include <conio.h>
int global = 10;
void f1(int);
void f1_1(int);
void f2(void);
int main()
{
int x = 5;
printf("inside main file");
getch();
f1(x);
f2();
getch();
return 0;
}
file1.c:
#include <stdio.h>
#include <conio.h>
void f1(int x)
{
printf("\ninside file1 >> f1 and x = %i", x);
getch();
f1_1(x);
}
void f1_1(int x)
{
printf("\ninside file1 >> f1 >> f1_1 and x = %i", x);
getch();
}
file2.c:
#include <stdio.h>
#include <conio.h>
extern int global;
void f2()
{
printf("\ninside file2 >> f2 function , global var = %i", global);
getch();
}
当我编译它时,我收到了这些警告:
c|8|警告:函数“f1_1”的隐式声明;你的意思是“f1”吗? [-Wimplicit-function-declaration]
c|11|警告:'f1_1' 的类型冲突
我该怎么办?
【问题讨论】:
-
理想方式:将函数原型移动到不同的
.h文件并包含在任何需要的地方,否则在f1之前定义f1_1。 -
请注意,在这种情况下,C 和 C++ 之间存在很大差异:在 C++ 中,您不会收到警告,而是收到错误。今后,请仅标记您正在使用的实际编程语言。
标签: c codeblocks