什麼是 C 中的“靜態”函數? - What is a “static” function in C?

問題:

The question was about plain c functions, not c++ static methods, as clarified in comments.問題是關於普通c函數,而不是c++ static方法,如註釋中所述。

I understand what a static variable is, but what is a static function?我明白什麼是static變量,但什麼是static函數?

And why is it that if I declare a function, let's say void print_matrix , in let's say ac (WITHOUT ah ) and include "ac" - I get "print_matrix@@....) already defined in a.obj" , BUT if I declare it as static void print_matrix then it compiles?爲什麼如果我聲明一個函數,讓我們說void print_matrix ,讓我們說ac (沒有ah )幷包含"ac" - 我得到"print_matrix@@....) already defined in a.obj" ,但是如果我將它聲明爲static void print_matrix那麼它會編譯嗎?

UPDATE Just to clear things up - I know that including .c is bad, as many of you pointed out.更新只是爲了解決問題-正如你們中的許多人指出的那樣,我知道包括.c是不好的。 I just do it to temporarily clear space in main.c until I have a better idea of how to group all those functions into proper .h and .c files.我只是爲了暫時清除main.c空間,直到我更好地瞭解如何將所有這些函數分組到正確的.h.c文件中。 Just a temporary, quick solution.只是一個臨時的、快速的解決方案。


解決方案:

參考一: https://stackoom.com/question/2LBy
參考二: What is a “static” function in C?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章