相同字符串文字的内存分配

问题描述 投票:0回答:0

考虑这段代码:

int main(void)
{
    printf(%s, "the string");
    printf(%s, "the string");
}

是否有任何标准说程序内存只会为

"the string"
分配一次而不是两次(或任何其他次数,具体取决于使用文字的次数)?当我检查我的程序的输出 elf 文件时,对于这种情况,我只能找到只出现一次的字符串,我试图弄清楚这是一个规则,还是依赖于编译器。

c string compilation literals
© www.soinside.com 2019 - 2024. All rights reserved.