為什么在test.c中,要將整個(gè)函數(shù)設(shè)定為static,而不能只將printLine設(shè)定為static
#include <stdio.h>
static void say(){
??? printLine();
??? printf("I love imooc\n");
??? printf("good good study!\n");
??? printf("day day up!\n");
??? printLine();
}
#include <stdio.h>
static void say(){
??? printLine();
??? printf("I love imooc\n");
??? printf("good good study!\n");
??? printf("day day up!\n");
??? printLine();
}
2020-06-26
舉報(bào)
2020-06-26
test.c中是say()函數(shù)的具體說明與實(shí)現(xiàn);hello.c中的main函數(shù)中有內(nèi)部函數(shù)也是say()函數(shù),而hello.c的頭文件中已經(jīng)包含了"test.c",這樣會(huì)讓編譯器認(rèn)為say()函數(shù)定義了兩次,所以,只能在test.c中定義say()函數(shù)為static,說明此函數(shù)作用域只在test.c中使用。