English 中文(简体)
C 说明连接字面
原标题:C string literals linking

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.

最佳回答

联系人必须合并任何东西。 它只是要把申报的类型描绘成一种界定的类型。 这需要找到界定的类型,填充所抵消的地址以跳跃到正确的项目上。

你们所说的话将是最佳的联系人。 很多联系人根本不优化,而那些没有被搁置到最优化标准的人,因此,你永远无法在所观察到的联系人发现的调查结果之外(当时该机器)。

问题回答

实际上,这些网站can t显示了同样的记忆,因为你可以写信给他们。

现在,如果说:

char *s1 = "MyString";
char *s2 = "MyString";

确实是possible <>>em>:s1 = s2。 不要认为它是有保障的。

我可能不会指望它,因为它是编纂者,取决于如何解决象征问题。 多数汇编者都创造了一个连续剧的事例,然后简单地提到,但我并不取决于这一点,因为有时情况并非如此。 我个人想在你的锁定和锁定方法中使用像这样的扼杀。 也许会更好地为你们服务。

我认为你正处在错误的轨道上。 联系人不仅 t倒了不同汇编单位的字面,而且很可能甚至为它们创造了外部象征。

即使在同一个汇编股内,汇编者可<>m>将同一字面上的两处事件合并为一例,但不必这样做:

It is unspecified whether these arrays are distinct provided their elements have the appropriate values.

现在看来是你提出问题的真正问题。 在C中,根据铺设字面打上锁锁/锁料,可能不是一个好的想法。 如你所说,这种倾向是用<代码>switch或类似的 st。

更自然的是,有锁的类型,宣布一个全球变量,为你各自独特的24小时/全天活动提供可区分的名称。 这迫使你以你所有汇编单位所看到的方式宣布每次此类活动,并抽出一个汇编单位,由你实际界定。





相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...