為什么第三行的代碼要用 static 而不是 extern ?
#include <stdio.h>
extern void printLine();
static void say()
{
? ? printLine();
? ? printf("I love imooc\n");
? ? printf("good good study!\n");
? ? printf("day day up!\n");
? ? printLine();
}
#include <stdio.h>
extern void printLine();
static void say()
{
? ? printLine();
? ? printf("I love imooc\n");
? ? printf("good good study!\n");
? ? printf("day day up!\n");
? ? printLine();
}
2021-03-07
舉報(bào)
2021-10-22
因?yàn)榈谌惺莾?nèi)部的 外部是*
2021-03-09
本人新手,目前是這樣理解的,要是不對(duì)望大神指點(diǎn)
#include?"test.c"???//引用test.c文件----#include的作用純粹就是內(nèi)容拷貝,運(yùn)行時(shí)被包含文件test.c中的文本將替換源代碼文件中的#include 指令;用extern定義say()函數(shù),程序運(yùn)行時(shí)相當(dāng)于hello.c與test.c中都定義了外部函數(shù)say(),而C語(yǔ)言規(guī)定不允許有同名的外部函數(shù),所以編譯會(huì)報(bào)錯(cuò)。
不使用#include?"test.c"時(shí)則需用extern定義say()函數(shù):
hello.c
test.c