沒有運(yùn)行結(jié)果也對!!
#include <stdio.h>
#include "test.c" //引用test.c文件
extern void printLine()
//這里定義的方法對嗎?
{
??? printf("**************\n");
}
int main()
{
??? say();
??? return 0;
}
怎么沒有運(yùn)行結(jié)果??
#include <stdio.h>
#include "test.c" //引用test.c文件
extern void printLine()
//這里定義的方法對嗎?
{
??? printf("**************\n");
}
int main()
{
??? say();
??? return 0;
}
怎么沒有運(yùn)行結(jié)果??
2015-04-12
舉報
2016-01-22
因?yàn)槲募ello.c的printLine()函數(shù)和test.c中的say()函數(shù)是被相互引用的,因此這兩個函數(shù)都應(yīng)為外部函數(shù),在兩個文件中都必須聲明引用。所以小編的答案是錯誤的!具體代碼如下:
補(bǔ)充:extern的主要作用不在于定義外部變量或函數(shù),而在于引用定義,如果在其他編譯器中去掉#include”test.c",不然會出現(xiàn)重定義(例如visual studio)。
hello.c文件中:
#include <stdio.h>
#include "test.c"?? //引用test.c文件
extern void say();
void printLine()???? //這里定義的方法對嗎?
{
?? printf("**************\n");??
}
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();
}
2015-04-13
有運(yùn)行結(jié)果啊,你是不是在本地寫的?如果在本地寫的話,那么你需要有test.c這個源文件