9 Star 20 Fork 9

OpenHarmony / appexecfwk_interfaces_innerkits_appexecfwk_lite

【讨论】头文件定义`static int`常量,感觉有点不合理

任务
已完成
Gymee  Opened this issue

该问题是怎么引起的?

头文件定义static int常量,感觉不是很合理哈,可以一起讨论一下

重现步骤

不涉及

报错信息

在头static int常量会使得在包含它的.c或者.cpp文件中都定义一个变量,会导致额外的ram/rom开销;另外从使用常量的角度上看不应该定义在interfaces_innerkits这种目录下面

// when installLocation set 1, it means install dir is storage/app
const static int32_t INSTALL_LOCATION_INTERNAL_ONLY = 1;
// when installLocation set 2, it means install dir is sdcard/app
const static int32_t INSTALL_LOCATION_PREFER_EXTERNAL = 2;

可以使用enum,这样更好一点

enum {
   // when installLocation set 1, it means install dir is storage/app
   INSTALL_LOCATION_INTERNAL_ONLY = 1,
   // when installLocation set 2, it means install dir is sdcard/app
   INSTALL_LOCATION_PREFER_EXTERNAL = 2,  
};
+1 9
Attachments
total 2 participants

Comments (2)

wangzhen 2020-09-12 09:55 member

有道理

wangzhen 2020-09-18 11:31 member

已完成

Sign in to comment

Assignees
Labels
Not set
Projects
Milestones
Branches
Planed to start
Planed to end
Top level
Priority
1
https://git.oschina.net/openharmony/appexecfwk_interfaces_innerkits_appexecfwk_lite.git
git@git.oschina.net:openharmony/appexecfwk_interfaces_innerkits_appexecfwk_lite.git
openharmony
appexecfwk_interfaces_innerkits_appexecfwk_lite
appexecfwk_interfaces_innerkits_appexecfwk_lite

Search