gpt4 book ai didi

c - 函数在可执行文件中的位置

转载 作者:太空狗 更新时间:2023-10-29 15:24:39 25 4
gpt4 key购买 nike

C 标准是否要求编译(和链接)二进制文件中的函数将按照它们在 C 文件中写入的顺序出现?

Please assume that in the example below the compiler did not remove / inline any function, and they all exist in the binary. the question is not about what the compiler might do with empty function, but about the order of the functions.

例如,如果我编译 example.c:

void bar() {  }
void foo() { bar(); }
int main() { foo(); }

我可以确定 foo 会出现在输出文件中的 bar 之后吗?

最佳答案

不,C 标准中没有这样的要求。在编译和链接方面,只有函数的特定属性,如外部链接或静态链接等被明确提及,但即使是这些也大多以与实现无关的方式描述。到目前为止,在任何标准文档中都没有条款(据我所知)强加了对可执行文件中符号顺序的期望。

关于c - 函数在可执行文件中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14113809/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com