我有一个庞大的 type-def 数组,我希望它可以跨多个 c 文件访问。type-def 的定义在头文件中。共享数据的最佳方法是什么。我应该将其存储在头文件还是 ac 文件中?
方法一
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);
方法二
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);