As far as I am aware, the linker tries to merge two string literals into one single literal, if they are both the same, e.g.:
档案1.c
char const* firstString = "foo";
档案2.c
char const* secondString = "foo";
只会产生<代码>foo 在各自的记忆科(储蓄4 By)。 这对于嵌入式应用特别重要(如avr-gcc
vsgcc
.
但是,我很想知道,我是否能够实际依靠这一点,并相信,如果两条扼杀手段平等,他们的指使也是平等的(条件是,在整个方案中,你只穿透字面,而且不存在时间间隔——这是我案例的合理假设)。 显然,我要加快速度比较,并允许一个常用的职能获得一个像样的明显字面:
void lock(char const*);
void unlock(char const*);
lock("test");
dosmth();
unlock("test");
In essence, I want to avoid having a huge enum and huge switches inside the lock
/unlock
functions.