qq_慕圣134250
2018-12-15 17:13
为什么运行失败?求大神指导。
#include <stdio.h>
#include "test.c" //引用test.c文件
extern void printLine()
{
printf("**************\n");
}
int main()
{
say();
return 0;
}
这个是hello.c中的代码,另外在test.c中 void say() 默认是外部函数,但是在hello.c中第二行又引用了test.c其实是没必要的。说白了就是人家本来就是外部函数可以直接调用但是你又引用了他的文件。
两种可以方法解决:
hello.c中把第二行引用test.c注释掉;
test.c中把void say()定义为内部函数即static void say() 。
问题倒可以解决,但是并不确定也不明白为什么外部函数和引用文件会有冲突,可能跟编译器有关吧。
hello.c中
#include <stdio.h>
void printLine() //这里定义的方法对吗?
{
printf("**************\n");
}
extern void say();
int main()
{
say();
return 0;
}
test.c中
#include <stdio.h>
extern void printLine();
void say()
{
printLine();
printf("I love imooc\n");
printf("good good study!\n");
printf("day day up!\n");
printLine();
}C语言入门
928218 学习 · 21546 问题
相似问题