我有一個龐大的type-def數組,我希望它可以跨多個c文件訪問。 type-def的定義在頭文件中。什麼是共享數據的最佳方法..我應該將其存儲在頭文件還是存儲在c文件中?C中使用多個文件的數據存儲
方法我
project.h
---------
typedef struct td_myproject{
lot of fields ....
} td_myproject;
projectdata.h
-------------
include "project.h"
td_myproject myproject[] = {
over 100k of recs with data filled before compilation
}
myproject.c
-----------
include "project.h"
include "projectdata.h"
(with proper guard usage)
print(%s",myproject[0].field1);
方法2
project.h
---------
typedef struct td_myproject{
lot of fields ....
} td_myproject;
projectdata.c
-------------
include "project.h"
td_myproject myproject[] = {
over 100k of recs with data filled before compilation
}
myproject.c
-----------
include "project.h"
(with proper guard usage)
print(%s",myproject[0].field1);
數據是靜態的還是有可能改變? – wmorrison365