C檔案的static屬性

2021-08-21 17:56:19 字數 705 閱讀 8387

main.c中有如下定義:

#include 

#include "test.h"

typedef

struct data_t;

typedef

enumstate_e;

static

void printmain(int val)

int main(void)

test.c檔案中:

#include 

#include "test.h"

#define test_a = 91

int test_b = 55;

typedef

structdata_t;

typedef

enumstate_e;

static

void printtest(int val)

void output(int val)

輸出結果為:main.c中printmain列印1,test.c中output列印b

由於型別定義以及巨集在編譯後不生成符號表,所以在main.c檔案中有重複定義也不會引起衝突;

而變數和函式會生成符號表,在鏈結時會引發衝突;

如果型別的定義放在test.h標頭檔案中,則會引發重定義錯誤;

static修飾屬性

今天寫程式遇到一點小問題,最後問題出在成員變數修飾符上,static修飾符 public class students public int getid public void setid int id public string getname public void setname string...

定義static屬性

在所有定義的方法上以及屬性上實際上都可以使用static關鍵字進行定義。1.static屬性 在講解具體的static操作之前首先來看這樣的乙個程式 範例 定義乙個表示人的類,同時設定他所在的國家 class person public string getinfo public class tes...

static修飾的類屬性

我看書上說 static成員總是唯一存在的,並且在多個物件之間互享。因此想到,如果我在a.php中例項化了person.class.php這個類,並給static name賦值,那麼在b.php中再次例項化這個類,b中能不能讀取name屬性的新值呢?如下 person.class.php class...